# BBC BASIC Programmers' Reference

### Site Tools

generating_20pseudo-random_20numbers

# Differences

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

 generating_20pseudo-random_20numbers [2018/03/31 13:19]127.0.0.1 external edit generating_20pseudo-random_20numbers [2018/04/13 10:43] (current)richardrussell 2018/04/13 10:43 richardrussell 2018/03/31 13:19 external edit 2018/04/13 10:43 richardrussell 2018/03/31 13:19 external edit Line 38: Line 38: mov  [seed],eax mov  [seed],eax ret ret - You can test the code from BASIC as follows:\\ \\ + You can test the code from BASIC as follows: + +  ​ CALL Randomise CALL Randomise FOR I% = 1 TO 20 FOR I% = 1 TO 20 PRINT ~ USR(Rnd) PRINT ~ USR(Rnd) NEXT NEXT + ​ + ==== RND(N) ==== ==== RND(N) ==== \\  The subroutine below provides a direct equivalent to RND(N), where N is a positive integer greater than 1. Each time it is called it returns a pseudo-random integer in the range 1 to N, in the eax register:\\ \\ \\  The subroutine below provides a direct equivalent to RND(N), where N is a positive integer greater than 1. Each time it is called it returns a pseudo-random integer in the range 1 to N, in the eax register:\\ \\ Line 58: Line 62: inc  eax inc  eax ret ret - The parameter N is passed to the subroutine in the ebx register. If you prefer to return a number in the range 0 to N-1 just delete the **inc eax** instruction.\\ \\  You can test the code from BASIC as follows:\\ \\ + The parameter N is passed to the subroutine in the ebx register. If you prefer to return a number in the range 0 to N-1 just delete the **inc eax** instruction.\\ \\  You can test the code from BASIC as follows: + +  ​ CALL Randomise CALL Randomise FOR I% = 1 TO 20 FOR I% = 1 TO 20 Line 64: Line 70: PRINT USR(RndRange) PRINT USR(RndRange) NEXT NEXT + ​ + ==== RND(1) ==== ==== RND(1) ==== \\  The subroutine below provides a direct equivalent to RND(1). Each time it is called it returns a pseudo-random 64-bit floating-point value (double) in the range 0.0 to 1.0:\\ \\ \\  The subroutine below provides a direct equivalent to RND(1). Each time it is called it returns a pseudo-random 64-bit floating-point value (double) in the range 0.0 to 1.0:\\ \\ Line 82: Line 90: mov  [ebx+4],ecx mov  [ebx+4],ecx ret ret - The value is returned in memory at the address passed in the ebx register.\\ \\  You can test the code from BASIC as follows:\\ \\ + The value is returned in memory at the address passed in the ebx register.\\ \\  You can test the code from BASIC as follows: + +  ​ CALL Randomise CALL Randomise FOR I% = 1 TO 20 FOR I% = 1 TO 20 Line 89: Line 99: PRINT R# PRINT R# NEXT NEXT +
generating_20pseudo-random_20numbers.txt · Last modified: 2018/04/13 10:43 by richardrussell

### Page Tools 