random number algorithm
Posted: Wed Nov 26, 2003 6:00 am
Does anyone have a randomnumber algorythm that produces better results than the one found in PB?
http://www.purebasic.com
https://www.purebasic.fr/english/
I, personally, can't imagineDoes anyone have a randomnumber algorythm that produces better results than the one found in PB?
Code: Select all
RandomSeed(gettickcount_())
OpenWindow(0, 0, 0, 800, 600, 0, "Random Test")
StartDrawing(WindowOutput())
Repeat
Plot(Random(800), Random(600))
ForEver
Shot down!!Psychophanta wrote:What RGB() function do is return the three parameters as bytes of a 24bit number.
So better and faster is:
Plot(Random(800), Random(600),Random($FFFFFF))
Code: Select all
RandomSeed(gettickcount_())
OpenWindow(0, 0, 0, 800, 600, 0, "Random Test")
StartDrawing(WindowOutput())
temp.l=gettickcount_()
For a = 1 To 500000
Plot(Random(800), Random(600),Random($FFFFFF))
Next
z = gettickcount_() - temp
temp.l=gettickcount_()
For a = 1 To 500000
Plot(Random(800), Random(600),RGB(Random(255),Random(255),Random(255)))
Next
x = gettickcount_() - temp
col.l=$FFFFFF
temp.l=gettickcount_()
For a = 1 To 500000
Plot(Random(800), Random(600),Random(col))
Next
c = gettickcount_() - temp
CloseWindow(0)
OpenConsole()
PrintN(Str(z))
PrintN(Str(x))
PrintN(Str(c))
Input()
CloseConsole()
End
Code: Select all
RandomSeed(gettickcount_())
OpenWindow(0, 0, 0, 800, 600, 0, "Random Test")
StartDrawing(WindowOutput())
zz=1000
xx=1000
cc=1000
dd=1000
ee=1000
ff=1000
gg=1000
For b= 1 To 10
temp.l=gettickcount_()
For a = 1 To 500000
Plot(Random(800), Random(600),Random($FFFFFF))
Next
z = gettickcount_() - temp
If z<zz
zz=z
EndIf
temp.l=gettickcount_()
For a = 1 To 500000
Plot(Random(800), Random(600),RGB(Random(255),Random(255),Random(255)))
Next
x = gettickcount_() - temp
If x<xx
xx=x
EndIf
col.l=$FFFFFF
temp.l=gettickcount_()
For a = 1 To 500000
Plot(Random(800), Random(600),Random(col))
Next
c = gettickcount_() - temp
If c<cc
cc=c
EndIf
coll.b=$FF
temp.l=gettickcount_()
For a = 1 To 500000
Plot(Random(800), Random(600),Random(coll))
Next
d = gettickcount_() - temp
If d<dd
dd=d
EndIf
temp.l=gettickcount_()
For a = 1 To 500000
Plot(Random(800), Random(600),Random($FFFFFF))
Next
e = gettickcount_() - temp
If e<ee
ee=e
EndIf
temp.l=gettickcount_()
For a = 1 To 500000
Plot(Random(800), Random(600),Random(16777215))
Next
f = gettickcount_() - temp
If f<ff
ff=f
EndIf
colll.f=$FFFFFF
temp.l=gettickcount_()
For a = 1 To 500000
Plot(Random(800), Random(600),Random(colll))
Next
g = gettickcount_() - temp
If g<gg
gg=g
EndIf
Next b
CloseWindow(0)
OpenConsole()
PrintN("$FFFFFF "+Str(zz))
PrintN("RGB "+Str(xx))
PrintN("Long "+Str(cc))
PrintN("Byte "+Str(dd))
PrintN("$FFFFFF "+Str(ee))
PrintN("16777215 "+Str(ff))
PrintN("Float "+Str(gg))
Input()
CloseConsole()
End