Linear congruential generator: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: increased font size for output.) |
(<lang julia></lang>) |
||
Line 1,529: | Line 1,529: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
{{works with|Julia|0.6}} |
|||
⚫ | |||
<lang Julia> |
|||
⚫ | |||
function lcg_maker{T<:Integer}(r::T, a::T, c::T, m::T, sh::T) |
|||
<lang julia>function getlgc(r::Integer, a::Integer, c::Integer, m::Integer, sh::Integer) |
|||
state = r |
state = r |
||
function |
return function lgcrand() |
||
state = mod(a*state + c, m) |
state = mod(a * state + c, m) |
||
return state >> sh |
return state >> sh |
||
end |
end |
||
return lcg_rand |
|||
end |
end |
||
seed, nrep = 0, 10 |
|||
⚫ | |||
seed = 0 |
|||
⚫ | |||
println("The first $nrep results for a BSD rand seeded with $seed:") |
|||
⚫ | |||
println(seed, ":") |
|||
@printf("%14d\n", bsdrand()) |
|||
⚫ | |||
println(@sprintf "%14d" bsd_rand()) |
|||
end |
end |
||
msrand = getlgc(seed, 214013, 2531011, 2 ^ 31, 16) |
|||
⚫ | |||
println() |
|||
⚫ | |||
⚫ | |||
@printf("%14d\n", msrand()) |
|||
println(seed, ":") |
|||
⚫ | |||
⚫ | |||
println(@sprintf "%14d" ms_rand()) |
|||
end |
|||
⚫ | |||
{{out}} |
{{out}} |
||
⚫ | |||
<pre> |
|||
⚫ | |||
12345 |
12345 |
||
1406932606 |
1406932606 |
||
Line 1,576: | Line 1,568: | ||
551188310 |
551188310 |
||
The first 10 results for a M$ rand |
The first 10 results for a M$ rand seeded with 0: |
||
38 |
38 |
||
7719 |
7719 |
||
Line 1,586: | Line 1,578: | ||
32285 |
32285 |
||
10450 |
10450 |
||
30612 |
30612</pre> |
||
</pre> |
|||
=={{header|K}}== |
=={{header|K}}== |