Pseudo-random numbers/Splitmix64: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 104:
 
=={{header|Ada}}==
Ada conversion of Next_float * 5.0 to an integer value resulted in some values of 5 which would have caused a buffer overflow in the counting array. The fix was to truncate Next_float * 5.0 as a floating point value and convert that value to an integer. Upon doing this the counts of each array element become 20073, indicating there are an equal number values in each portion of the random number range.
 
The random number functions are written in a stand-alone package. The package is split into a package specification defining the interfaces to the public subprograms and a body containing the implementation of the random number generator.
 
Line 161 ⟶ 159:
procedure Main is
subtype idx is Integer range 0 .. 4;
type answer_arr is array (idx) of Unsigned_64Natural;
Vec : answer_arr := (others => 0);
J : idxInteger;
fj : Float;
begin
Line 176 ⟶ 174:
for I in 1 .. 100_000 loop
fj := Float'Truncation (next_float * 5.0);
J := idxInteger (fj);
Vec (J) := Vec (J) + 1;
end loop;
 
for I in Vec'Range loop
Put_Line (I'Image & ":" & Unsigned_64Integer'Image (Vec (JI)));
end loop;
 
end Main;</lang>
</lang>
{{out}}
<pre>
Line 192 ⟶ 191:
4593380528125082431
16408922859458223821
0: 2007320027
1: 2007319892
2: 20073
3: 2007319978
4: 2007320030
</pre>
 
82

edits