Linear congruential generator: Difference between revisions

Content added Content deleted
Line 1,938: Line 1,938:


=={{header|Pascal}}==
=={{header|Pascal}}==
{{incorrect|Pascal|Incorrect output. [[User:Petelomax|Pete Lomax]] ([[User talk:Petelomax|talk]])}}
<lang pascal>Program LinearCongruentialGenerator(output);
<lang pascal>Program LinearCongruentialGenerator(output);
{$mode iso}

var
var
x1, x2: int64;
x1, x2: int64;

function bsdrand: longint;
function bsdrand: cardinal;
const
const
a = 1103515245;
a = 1103515245;
Line 1,953: Line 1,952:
bsdrand := x1;
bsdrand := x1;
end;
end;

function msrand: longint;
function msrand: cardinal;
const
const
a = 214013;
a = 214013;
Line 1,963: Line 1,962:
msrand := x2 div 65536;
msrand := x2 div 65536;
end;
end;

var
var
i: longint;
i: cardinal;
begin
begin
writeln(' BSD MS');
writeln(' BSD MS');
Line 1,972: Line 1,971:
for i := 1 to 10 do
for i := 1 to 10 do
writeln(bsdrand:12, msrand:12);
writeln(bsdrand:12, msrand:12);
end.</lang>
end.
</lang>
Output:
Output:
<pre> BSD MS
<pre> BSD MS
12345 7584
12345 38
1124652145 3277
1406932606 7719
1499545833 3067
654583775 21238
1558406049 31446
1449466924 2437
696007321 13069
229283573 8855
56579025 17343
1109335178 11797
1312705865 2510
1051550459 8365
811881729 5264
1293799192 32285
1301653753 21298
794471793 10450
1318262577 27689</pre>
551188310 306129</pre>


=={{header|Perl}}==
=={{header|Perl}}==