# BBC BASIC Programmers' Reference

### Site Tools

alternative_20pseudo-random_20numbers

# Differences

This shows you the differences between two versions of the page.

 alternative_20pseudo-random_20numbers [2018/03/31 13:19]127.0.0.1 external edit alternative_20pseudo-random_20numbers [2018/04/17 15:05] (current)tbest3112 Added syntax highlighting 2018/04/17 15:05 tbest3112 Added syntax highlighting2018/03/31 13:19 external edit 2018/04/17 15:05 tbest3112 Added syntax highlighting2018/03/31 13:19 external edit Line 5: Line 5: \\  The following routine generates a 32-bit pseudo-random number when called, the pseudo-random number is returned in the **eax** register:\\ \\ \\  The following routine generates a 32-bit pseudo-random number when called, the pseudo-random number is returned in the **eax** register:\\ \\ .seed     dd 1 :dd 0 .seed     dd 1 :dd 0 + ​ .Rand .Rand mov    eax, &​4C957F2D ​      ; | mov    eax, &​4C957F2D ​      ; | Line 75: Line 75: ===== Calling the pseudo-random number generator from BASIC ===== ===== Calling the pseudo-random number generator from BASIC ===== \\  These routines may be called from BASIC, instead of using the **RND** function, if you //really// want to:\\ \\ \\  These routines may be called from BASIC, instead of using the **RND** function, if you //really// want to:\\ \\ + result% = USR Rand :REM Return a pseudo-random number in result% result% = USR Rand :REM Return a pseudo-random number in result% SYS RandFloat, ^N# :REM Return a pseudo-random float in N# SYS RandFloat, ^N# :REM Return a pseudo-random float in N# SYS RandRange, N TO result% :REM Return a range limited pseudo-random number in result% SYS RandRange, N TO result% :REM Return a range limited pseudo-random number in result% SYS RandSeed, TIME, TIME :REM Seed the pseudo-random generator using TIME SYS RandSeed, TIME, TIME :REM Seed the pseudo-random generator using TIME + ​ \\ \\ ===== References ===== ===== References ===== \\  The multiplier [[http://​www.google.co.uk/​search?​q=6364136223846793005|6364136223846793005]] was obtained from Knuth, D.E., [[http://​www.amazon.co.uk/​gp/​product/​0201896842/​302-0106311-7812866|"​The Art of Computer Programming,"​ Vol 2, Seminumerical Algorithms]],​ Third edition, Addison-Wesley,​ 1998, p. 106 (line 26) & p. 108. \\  The multiplier [[http://​www.google.co.uk/​search?​q=6364136223846793005|6364136223846793005]] was obtained from Knuth, D.E., [[http://​www.amazon.co.uk/​gp/​product/​0201896842/​302-0106311-7812866|"​The Art of Computer Programming,"​ Vol 2, Seminumerical Algorithms]],​ Third edition, Addison-Wesley,​ 1998, p. 106 (line 26) & p. 108.
alternative_20pseudo-random_20numbers.txt ยท Last modified: 2018/04/17 15:05 by tbest3112