To simplify I looked at FB's Rnd as our generator and used Cast(Ulong, Rnd*2^32) as our 32-bit random number.
If we do a bucket load of '(Cast(Ulong, Rnd*2^32) Mod (Two-One+1)) + One' we should tend to (Two+One)/2.
So, consider this:
Code: Select all
Dim As Long One, Two, i, j
Dim As Double tot
Randomize
One = 100 : Two = 400
Print (Two+One)/2
Print
For i = 1 to 10
tot = 0
For j = 1 to 10^8
tot += (Cast(Ulong, Rnd*2^32) Mod (Two-One+1)) + One
Next
tot = tot/10^8
Print tot
Next
Print
Print "Done"
Sleep
Code: Select all
250
250.01042134
249.98906134
250.01741886
249.99888382
250.01529021
249.98313448
249.99826763
249.98206929
250.00873917
249.99681567
Done
However, if we use One = -857 and Two = 857 I get
Code: Select all
0
2146046036.586742
2146303777.516746
2146107025.05562
2146282474.496294
2146310477.693399
2146113081.000696
2145999049.627478
2146383019.678879
2146562334.515463
2146294414.559095
Done
How about One = -100 and Two = -50 I get
Code: Select all
-75
4294967222.172671
4294967222.169378
4294967222.173999
4294967222.173287
4294967222.172093
4294967222.172445
4294967222.170393
4294967222.172475
4294967222.173421
4294967222.172063
Done
For example if we added 862 to -857 and 857 and then subtracted 862 at the end I get
Code: Select all
0.04980794999999999
-0.01776288999999998
0.009281009999999978
-0.00547114999999998
0.09483583000000001
0.04208870999999997
-0.02586748999999999
0.03212702000000001
0.01198539999999998
0.01648302000000002
Adding 105 to -100 and -50 and then subtract 105 I get
Code: Select all
-75.00048656
-74.99729623
-74.99963022
-74.99998549
-74.99852961000001
-74.99874134
-75.00022214000001
-75.00174626
-75.00139839000001
-75.00080697999999