Your example does NOT produce a more random distribution. So I guess you fail too:) Any random number generator that uses % (mod) will not work. Here is a simple proof: Take a piece of wood, 10 inches long. Using a saw, cut it into 3 inch lenghts. Stack all 4 pieces on top of each other. What you get is that 3 of the parts stack perfectly, but you have on left over little bit of 1 inch, that makes part of the stack higher. Now imagine a number line of ten numbers being this bit of wood. The numbers chosen are from one to three (the mod 3 part), thus the 3 inch cuts (each inch is one integer). You should beable to see the the number 1 has 4 chances, and the number 2 and 3 has only 3 with a number generator that generated numbers from 1 to 10.
So, thus you must ALWAYS scale the random() results, not use mod. so (random() * (max desired + 1)) / (max value returned by random + 1) or something close to that.
Your example does NOT produce a more random distribution. :)
So I guess you fail too
Any random number generator that uses % (mod) will not work.
Here is a simple proof:
Take a piece of wood, 10 inches long.
Using a saw, cut it into 3 inch lenghts.
Stack all 4 pieces on top of each other.
What you get is that 3 of the parts stack perfectly, but you have on left over little bit of 1 inch, that makes part of the stack higher.
Now imagine a number line of ten numbers being this bit of wood. The numbers chosen are from one to three (the mod 3 part), thus the 3 inch cuts (each inch is one integer).
You should beable to see the the number 1 has 4 chances, and the number 2 and 3 has only 3 with a number generator that generated numbers from 1 to 10.
So, thus you must ALWAYS scale the random() results, not use mod. so (random() * (max desired + 1)) / (max value returned by random + 1) or something close to that.