Linear congruential generator: Difference between revisions

m (grammar)
Line 33:
 
(Here should be some sample numbers for a few seeds, so that one who solves this task can check if one's numbers matches these samples.)
 
=={{header|Icon}} and {{header|Unicon}}==
The following were written before the task was complete and may need adjustment.
Both behave in basically the same way. The LCRNG maintains the state (seed) from round to round. The seed can be changed by specifing an argument. Otherwise it defaults. Also these must be tested for 32 bit overflow (see Discussion / Talk pages).
<lang Icon>
procedure rand_BSD(x)
static seed,m
initial {
seed := 0 # default if no x given??
m := 2^31-1
}
seed := \x
seed := (1103515245 * seed + 12345) % m
return seed
end
 
 
procedure rand_MS(x)
static seed,m,d
initial {
seed := 0 # default if no x given??
m := 2^31-1
d := 2^16
}
 
seed := \x
seed := (214013 * seed + 2531011) % m
return seed/d
end</lang>
 
=={{header|PARI/GP}}==
Anonymous user