I have used your code, but adjusted the myrand with int(~~) , to give a more uniform distribution, which is shown.
Also, I have noticed a little error in my previous range functions, (the positions of the brackets within)
My gripe is not with the mode of getting rnd(), but with the way gcc seems to fail within high ranges.
This seems OK with -gen gas, but fails with -gen gcc, try with 64 bit fbc for example.
Code: Select all
dim as ulongint k=-1
k=k\2-5
'4294967295 ulong max
'18446744073709551615 ulongint max
dim as ulongint offset=12345678909876543210
Dim As ulongint MyMin=0, MyMax=5, MyRand
mymin=offset+mymin
mymax=offset+mymax
print mymin;" to ";mymax
dim as ulong a(0 to mymax - mymin)
dim as ulongint errors
Dim As ulongint MyRange=(MyMax-MyMin)
for i As integer=1 to 10000000
''MyRand=Rnd()*MyRange+MyMin
MyRand=int(Rnd()*(MyRange+1))+MyMin
if myrand>mymax then errors+=1
if myrand<mymin then errors+=1
a(mymax-myrand)+=1
next
print "distribution"
for n as long=lbound(a) to ubound(a)
print n, a(n)
next
print "errors ";errors
sleep