LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Random Numbers

Root / Submissions / [.]

12Me21Created:
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()

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.

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.

Replying to:snail_
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.
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

Replying to:snail_
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.
Additionally, the RNGs on Wii U and 3DS produce different outputs. This is much less of a surprise.

Replying to:snail_
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.
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.