[bb] RND substitute by jfk EO-11110 [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:43

Previous topic - Next topic

BlitzBot

Title : RND substitute
Author : jfk EO-11110
Posted : 1+ years ago

Description : 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.


Code :
Code (blitzbasic) Select
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 :


_33(Posted 1+ years ago)

 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.... ????


Azathoth(Posted 1+ years ago)

 You're overwriting 'rnd_st$' :rnd_st$=Abs(rnd_inc)rnd_st$=Right$("000000"+Abs(rnd_inc),6)