system_random_1.0.0_3db7f76e/example/src/system_random_example.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
with Ada.Unchecked_Conversion;

with Ada.Streams; use Ada.Streams;
with Ada.Text_IO; use Ada.Text_IO;
with System_Random;

procedure System_Random_Example is
   package Streams_Random is new System_Random
     (Element       => Stream_Element, Index => Stream_Element_Offset,
      Element_Array => Stream_Element_Array);

   --  We have to make sure that byte sizes of both parameters are equal
   function Convert is new Ada.Unchecked_Conversion
     (Stream_Element_Array, Integer);

   use Streams_Random;

   Random_Values : aliased Stream_Element_Array := (0 .. 3 => 0);
begin
   Random (Random_Values); --  Fill with random data
   Put_Line ("Random integer: " & Convert (Random_Values)'Image);
end System_Random_Example;