-
-
Notifications
You must be signed in to change notification settings - Fork 9
mt19937
IsaacShelton edited this page Nov 13, 2022
·
6 revisions
2.7/mt19937.adept
is a 32-bit implementation of the MT19937 Pseudo Random Number Generator
define MT19937_MAX = 4294967295 // Maximum possible random value (inclusive)
define MT19937_RANGE = MT19937_MAX + 1 // Number of possible random values
-
func mt19937Seed(seed uint) void
Seeds the MT19937 Pseudo-Random Number Generator.
-
func mt19937Random() uint
Returns a random number in the range
[0, MT19937_MAX]
using the MT19937 Pseudo-Random Number Generator.
By default, 2.7/random.adept
will use MT19937 to generate random numbers instead of libc srand()
/rand()
.
For most cases, using 2.7/random.adept
is recommended over 2.7/mt19937.adept
.
import 'sys/cstdio.adept'
import mt19937
func main {
// Seed PRNG with set seed
mt19937Seed(4357ui)
// Display first 2002 random numbers
repeat 2002 {
printf(' %10lu%s', mt19937Random(), idx % 7 == 6 ? '\n' : '');
}
}