View source code
Display the source code in std/random.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Struct std.random.LinearCongruentialEngine
Linear Congruential generator.
struct LinearCongruentialEngine(UIntType, UIntType a, UIntType c, UIntType m)
if (isUnsigned!UIntType);
Constructors
Name | Description |
---|---|
this
|
Constructs a LinearCongruentialEngine generator seeded with
x0 .
|
Properties
Name | Type | Description |
---|---|---|
front [get]
|
UIntType | Returns the current number in the random sequence. |
save [get]
|
typeof(this) |
Methods
Name | Description |
---|---|
opEquals
|
Compares against rhs for equality. |
popFront
|
Advances the random sequence. |
seed
|
(Re)seeds the generator. |
Example
Declare your own linear congruential engine
alias CPP11LCG = LinearCongruentialEngine!(uint, 48271, 0, 2_147_483_647);
// seed with a constant
auto rnd = CPP11LCG(42);
auto n = rnd .front; // same for each run
writeln(n); // 2027382
Example
Declare your own linear congruential engine
// glibc's LCG
alias GLibcLCG = LinearCongruentialEngine!(uint, 1103515245, 12345, 2_147_483_648);
// Seed with an unpredictable value
auto rnd = GLibcLCG(unpredictableSeed);
auto n = rnd .front; // different across runs
Authors
Andrei Alexandrescu Masahiro Nakagawa (Xorshift random generator) Joseph Rushton Wakeling (Algorithm D for random sampling) Ilya Yaroshenko (Mersenne Twister implementation, adapted from mir-random)
License
Copyright © 1999-2018 by the D Language Foundation | Page generated by ddox.