mardi 5 mars 2019

Randomly Weight element from array and pick it- in BASH

I want to pseudo-randomly pick one element from an array of 5 elements: I want to control the occurrence probability of each of those 5 elements.

Example: I have an array like this [A B C D E]

  • I want the probability to pick A: 0.10 (10%)
  • I want the probability to pick B: 0.10 (10%)
  • I want the probability to pick C: 0.20 (20%)
  • I want the probability to pick D: 0.20 (20%)
  • I want the probability to pick E: 0.40 (40%)

I have seen that I can Weight a random selection from an array here: Weighted random selection from array.

My question: how to weight elements contained on a array - in BASH?




Aucun commentaire:

Enregistrer un commentaire