Random Numbers ● SmileBASIC Source

Register

# Random Numbers

RND( [ channel , ] range ) - Returns a random integer from 0 to range-1 - range: Integer. Number of values to choose from. - channel: Integer 0-7 (Optional, defaults to 0). Randomizer channel to use. (SB has 8 independent randomizer "channels". Usually you'll just use the default channel, 0.) RNDF( [ channel ] ) - Returns a random number from 0 to 1 - channel: Integer 0-7 (Optional, defaults to 0). Randomizer channel to use. RANDOMIZE channel [ , seed ] - Sets the randomizer seed. - channel: Integer 0-7. Randomizer channel to re-seed. - seed: Integer (Optional, defaults to 0). The seed to use. (If 0, a random seed will be chosen).

# Examples:

Print a random number from 1 to 6: `PRINT RND(6)+1` This should be 0.20871972: ```RANDOMIZE 0,398 PRINT RNDF()```
Updated
Rating
5 Comment(s) snail_ QSP Contest 1 Contest Participant I participated in the first SmileBASIC Source QSP Contest! Helper Received for being very helpful around SmileBASIC Source Achievements Amazing Contributor Someone thinks I'm an awesome person who has done so much for the community! Achievements It's worth noting that for the same seed, each of the 8 generators will produce a different output. This is not something I expected so maybe someone with a bigger PRNG brain should look into it. The help page for RANDOMIZE refers to the generator ID as "random number series type" which totally flew under my radar until now. EDIT: Image is from BIG but this variance also occurs on 3DS. 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself I tested on the 3DS and this doesn't happen. ```FOR I=0 TO 7 RANDOMIZE I,100 ?RND(I,&H7FFFFFFF),RND(I,&H7FFFFFFF) NEXT``` snail_ QSP Contest 1 Contest Participant I participated in the first SmileBASIC Source QSP Contest! Helper Received for being very helpful around SmileBASIC Source Achievements Amazing Contributor Someone thinks I'm an awesome person who has done so much for the community! Achievements Additionally, the RNGs on Wii U and 3DS produce different outputs. This is much less of a surprise. snail_ QSP Contest 1 Contest Participant I participated in the first SmileBASIC Source QSP Contest! Helper Received for being very helpful around SmileBASIC Source Achievements Amazing Contributor Someone thinks I'm an awesome person who has done so much for the community! Achievements My first test method was wrong because I can't properly review my own code and I made a mistake. 12Me21 is correct so you can safely ignore the root comment. The RNGs are still different between BIG and 3DS though. Minxrod Third Year My account is over 3 years old Website Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Video Games I like to play video games! Hobbies Do you think you could add a note about syncing RNG in multiplayer? Like how you must make sure to use the same seed & channel or else games can desync? This has happened to me before, as it isn't an obvious problem.