Ich wollte gerade aus Interesse heraus eine Funktion schreiben, die einen Zufallswert liefert und bin dabei auf etwas interessantes in der Bascom-Hilfe gestoßen:
The RND() function returns an Integer/Word and needs an internal storage of 2 bytes. (___RSEED). Each new call to Rnd() will give a new positive random number.
Notice that it is a software based generated number. And each time you will restart your program the same sequence will be created.
You can use a different SEED value by dimensioning and assigning ___RSEED yourself:
Dim ___rseed as word : ___rseed = 10234
Dim I as word : I = rnd(10)
When your application uses a timer you can assign ___RSEED with the timer value. This will give a better random number.
Also kann man den Seed von der RND-Funktion direkt mit einem Timerwert laden, was für die Anwendung des Threadstarters einen ausreichenden Zufall darstellt.
![]()
Lesezeichen