Skip to content

mt19937

IsaacShelton edited this page Nov 13, 2022 · 6 revisions

mt19937

2.7/mt19937.adept is a 32-bit implementation of the MT19937 Pseudo Random Number Generator

Constants

define MT19937_MAX   = 4294967295       // Maximum possible random value (inclusive)
define MT19937_RANGE = MT19937_MAX + 1  // Number of possible random values

Functions

  • func mt19937Seed(seed uint) void

    Seeds the MT19937 Pseudo-Random Number Generator.

    [view src]

  • func mt19937Random() uint

    Returns a random number in the range [0, MT19937_MAX] using the MT19937 Pseudo-Random Number Generator.

    [view src]

Inclusion in '2.7/random.adept'

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.

Example Raw Usage

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' : '');
    }
}
Clone this wiki locally