I need to develop a function that has a one in a million chance to change one value in my application.
What I first thought was picking a number at the beginning, let's say 10 for example. Then, I call the function that uses Math.Random()
to generate a number between 1 and 1000000. I then compared the generated number to the number previously defined (10) and if they are equal the value changes, otherwise it remains the same.
However, I soon realized this did not work due to Math.Random()
working with doubles.
Is there any way I can do this? Or is there an alteration to what I've tried that I'm missing?
Thanks, guys!