Let's look at this piece-by-piece.
Rnd()
gives a number between 0 and 1.
So 5 * Rnd() + 1
gives a number between 1 and 6.
We can think of this number as being equally likely to be in one of 10 half-integer areas: [1,1.5], [1.5,2]...[5.5,6].
One of these will round to 1 - [1,1.5].
Two of these will round to 2 - [1.5,2] and [2,2.5].
3, 4 and 5 similarly have two of these which will round to them.
One of these will round to 6 - [5.5,6]
This explains the distribution you're seeing.
Therefore Round(6 * Rnd() + 0.5, 0)
should give you what you're looking for as it extends the area by half in both directions, so gives 1 and 6 the correct weightings.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments