dimanche 12 août 2018

How to randomly choose one of several strings?

I have this code:

letsdoit(something,'abcd');
letsdoit(something,'asdfasdf');
letsdoit(something,'gagaga');

I want it to be, if possible, just one simple line with the logic like:

(letsdoit(something,'abcd')) OR (letsdoit(something,'asdfasdf')) OR (letsdoit(something,'gagaga'));

so it has 33% chance to choose either of the three. Or:

(letsdoit(something,'abcd')) OR (letsdoit(something,'asdfasdf'))

so it has 50% chance to choose the left or 50% chance for the right thing.

My questions are:

  1. How to randomize between the three and only do one thing.

  2. How to randomize between two things and only do one.




Aucun commentaire:

Enregistrer un commentaire