January 19, 2021, 06:09:28 AM

### Author Topic: [bb] RND substitute by jfk EO-11110 [ 1+ years ago ]  (Read 751 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bb] RND substitute by jfk EO-11110 [ 1+ years ago ]
« on: June 29, 2017, 12:28:43 AM »
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
1. Graphics 640,480,32,2
2. SetBuffer FrontBuffer()
3.
4. Global rnd_inc
5.
6.
7. Repeat
8.  Plot  my_RND#(100,540), my_RND#(100,380)
9. Until KeyDown(1)
10.
11. End
12.
13.
14.
15.
16. Function my_RND#(v1#,v2#)
17.  rnd_inc=(rnd_inc)+(ScanLine()*MilliSecs()) Mod 3500000000
18.  rnd_st\$=Abs(rnd_inc)
19.  rnd_st\$=Right\$("000000"+Abs(rnd_inc),6)
20.  rnd_st\$="0."+rnd_st\$
21.  n#=v1+(Float(rnd_st\$)*(v2-v1))
22.  Return n
23. End Function

_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)