Random number generator (included): Difference between revisions

Content deleted Content added
imported>Arakov
Morn (talk | contribs)
→‎{{header|Kotlin}}: added Locomotive Basic
Line 517: Line 517:
=={{header|Kotlin}}==
=={{header|Kotlin}}==
As mentioned in the Java entry, the java.util.Random class uses a linear congruential formula and is not therefore cryptographically secure. However, there is also a derived class, java.security.SecureRandom, which can be used for cryptographic purposes
As mentioned in the Java entry, the java.util.Random class uses a linear congruential formula and is not therefore cryptographically secure. However, there is also a derived class, java.security.SecureRandom, which can be used for cryptographic purposes

=={{header|Locomotive Basic}}==
The Locomotive Basic RND function uses the firmware routine FLO RND from the floating-point pack to generate random numbers between 0 and 1. Memory addresses vary between different Amstrad CPC models, so the following hex addresses are for the CPC464: Calling &bd9d in RAM will jump to the FLO RND firmware routine in ROM at &2fb7. FLO RND then computes four random bytes and stores them at &b8e4 to &b8e7 in RAM. It does this by calling a helper function at &2ffa ''three'' times, to create two random bytes each time by repeated shifting and adding, which are then combined in a complicated-looking way to get four bytes.

To turn these random four bytes starting at &b8e4 into a five-byte floating-point number, the firmware then adds a single byte as the exponent and normalizes the resulting floating-point number with a jump to a routine at &36b1, which also returns execution to Basic.

CPCBasic on the other hand does not use the Amstrad CPC firmware at all, so it will not recreate the firmware algorithm's random numbers. It probably uses the built-in random number generator in JavaScript.

See documented CPC firmware code in Janneck, Jörn W. and Mossakowski, Till: ''ROM-Listing CPC464/664/6128'', Markt & Technik, 1986, p. 372/373. ISBN 3-89090-134-4 [https://www.cpcwiki.eu/index.php/ROM-Listing_CPC_464/664/6128]


=={{header|Lua}}==
=={{header|Lua}}==