Code archives/Algorithms/RND substitute
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
| This is pretty useless, however if you will ever need a function that does RND without to use Blitz's built in Rnd() function then this may be useful. Note: the sequences are NOT reproducable, so whenever you run it the numbers will differ. No smart maths here, just a simple overflow usage. | |||||
Graphics 640,480,32,2
SetBuffer FrontBuffer()
Global rnd_inc
Repeat
Plot my_RND#(100,540), my_RND#(100,380)
Until KeyDown(1)
End
Function my_RND#(v1#,v2#)
rnd_inc=(rnd_inc)+(ScanLine()*MilliSecs()) Mod 3500000000
rnd_st$=Abs(rnd_inc)
rnd_st$=Right$("000000"+Abs(rnd_inc),6)
rnd_st$="0."+rnd_st$
n#=v1+(Float(rnd_st$)*(v2-v1))
Return n
End Function |
Comments
| ||
| Do you know how SLOW it is to convert a numeric to a string, then use Right$, concatenate the string with something else, convert it back to numeric.... ???? |
| ||
| You're overwriting 'rnd_st$' : rnd_st$=Abs(rnd_inc) rnd_st$=Right$("000000"+Abs(rnd_inc),6) |
Code Archives Forum