+ 1
How can I make the ripeness more random?
The ripeness hovers around 1/2 (50%) Because of the rand()%2 changing 2 to other values results in a probability around 1/that value (the value%) But how can I make it more random? https://code.sololearn.com/c84t8STmZ20z/?ref=app
2 Réponses
+ 1
That depends on what you mean with "more random". One simple approach would be this:
Instead of modulo 2, choose any larger number n. Set a threshold t between 0 and n. If the result is larger than t, the mango is ripe.
Let's say you choose n = 100 and t = 65, the probability will now be around 65%. Not random enough? Randomize t as well!
If you want a more complex solution, check out the <random> header of C++. It implements different random number generators and probability distributions.
0
I also want to know how to make better random with python. I also cant recall things that a better educated person told me in IRC that related to the theory of random but I think its generally supposed to remain about 50%. Dont quote me.