Anonymous user
Linear congruential generator: Difference between revisions
<lang julia></lang>
m (→{{header|REXX}}: increased font size for output.) |
(<lang julia></lang>) |
||
Line 1,529:
=={{header|Julia}}==
{{works with|Julia|0.6}}
<tt>lcg_maker</tt> creates a linear congruential generator as a closure. This function is used to create the two generators called for by the task.▼
▲<tt>
<lang julia>function getlgc(r::Integer, a::Integer, c::Integer, m::Integer, sh::Integer)
state = r
return function
state = mod(a * state + c, m)
return state >> sh
end
end
▲bsd_rand = lcg_maker(seed, 1103515245, 12345, 2^31, 0)
@printf("%14d\n", bsdrand())
▲for i in 1:snum
end
▲print("The first ", snum, " results for a M\$ rand() seeded with ")
@printf("%14d\n", msrand())
end</lang>▼
▲for i in 1:snum
▲</lang>
{{out}}
▲The first 10 results for a BSD rand() seeded with 0:
12345
1406932606
Line 1,576 ⟶ 1,568:
551188310
The first 10 results for a M$ rand
38
7719
Line 1,586 ⟶ 1,578:
32285
10450
30612</pre>
=={{header|K}}==
|