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. When m = 0, no modulus is used.
						
				struct LinearCongruentialEngine(UIntType, UIntType a, UIntType c, UIntType m)
				
				  
				
				if (isUnsigned!UIntType);
						
					
				Constructors
| Name | Description | 
|---|---|
| this(x0) | 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 | 
|---|---|
| popFront() | Advances the random sequence. | 
| seed(x0) | (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 = rndExample
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 = rndExample
Declare your own linear congruential engine
// Visual C++'s LCG
alias MSVCLCG = LinearCongruentialEngine!(uint, 214013, 2531011, 0);
// seed with a constant
auto rnd = MSVCLCG(1);
auto n = rndAuthors
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-2024 by the D Language Foundation | Page generated by ddox.