|
Post by gatsby on Apr 5, 2022 9:59:05 GMT
Why is the final distribution always skewed towards lower values? Is it my coding or is the RND() function faulty?
' A program to make lots of numbers between 0 and 9, ' sum them, and show the results dim z(10) for x=1 to 1000000 y=int(rnd(1)*10) z(y)=z(y)+1 next x for x=0 to 9 print x;"=";z(x) next x print:Print "The End"
|
|
|
Post by plus on Apr 5, 2022 10:37:50 GMT
Yep rnd() is not the best. Over about 10000 not too bad. Lower numbers specially 0 do seem preferred.
Do you want some ideas for shuffling to make better?
|
|
|
Post by tsh73 on Apr 5, 2022 10:42:38 GMT
|
|
|
Post by tanger32au on Apr 5, 2022 10:55:59 GMT
Plays = 0
[RunProcess] print ""; Plays Plays = Plays + 1 NumRMD1 = INT(RND(1) * 10000) + 1
open "Log.txt" for append as #OutP1 print #OutP1, NumRMD1 close #OutP1 if NumRMD1 < 4999 then BigNumber = BigNumber + 1 if NumRMD1 > 5000 then SmallNumber = SmallNumber + 1 if NumRMD1 < 1000 then TinyNumber = TinyNumber + 1
If Plays = 1000 then gosub [EndProcess] else gosub [RunProcess]
[EndProcess] print "BigNumbers"; BigNumber print "SmallNumbers"; SmallNumber print "TinyNumbers"; TinyNumber notice "All done"
|
|
|
Post by plus on Apr 5, 2022 11:24:51 GMT
Here is a nice slow rand() function:
dim digits(9) for i = 0 to 9 ' load digits(i) = i next
'call shuff 'for i = 0 to 9 'print i, digits(i) 'next
'for i = 1 to 10 'print rand(0) 'next
dim z(10)
for x=1 to 100000 ' <<<<<<<<< you might want to reduce to 10,000 or 1000 for sampling and save time scan y=int(rand(1)*10) z(y)=z(y)+1 next x
for x=0 to 9 print x;"=";z(x) next x
print:Print "The End"
function rand(dummy) r = rnd(0) * 1000000 amt = len(str$(r)) for i = 1 to amt call shuff b$ = b$ + str$(digits(5)) next rand = val("." + b$) end function
sub shuff for i = 9 to 1 step -1 t = digits(i) r = int(rnd(0)*(i+1)) digits(i) = digits(r) digits(r) = t next end sub
|
|