Finite Field Arithmetic

ffa_rng.adb


   1 ------------------------------------------------------------------------------
   2 ------------------------------------------------------------------------------
   3 -- This file is part of 'Finite Field Arithmetic', aka 'FFA'.               --
   4 --                                                                          --
   5 -- (C) 2019 Stanislav Datskovskiy ( www.loper-os.org )                      --
   6 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html     --
   7 --                                                                          --
   8 -- You do not have, nor can you ever acquire the right to use, copy or      --
   9 -- distribute this software ; Should you use this software for any purpose, --
  10 -- or copy and distribute it to anyone or in any manner, you are breaking   --
  11 -- the laws of whatever soi-disant jurisdiction, and you promise to         --
  12 -- continue doing so for the indefinite future. In any case, please         --
  13 -- always : read and understand any software ; verify any PGP signatures    --
  14 -- that you use - for any purpose.                                          --
  15 --                                                                          --
  16 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm .     --
  17 ------------------------------------------------------------------------------
  18 ------------------------------------------------------------------------------
  19 
  20 with OS;  use OS;
  21 with FFA; use FFA;
  22 
  23 
  24 package body FFA_RNG is
  25    
  26    -- Prepare an RNG for use; at given path, or will use default
  27    procedure Init_RNG(RNG           : out RNG_Device;
  28                       RNG_Unix_Path : in  String := Default_RNG_Path) is
  29    begin
  30       begin
  31          -- Open the RNG at the offered path:
  32          Word_IO.Open(File => RNG.F,
  33                       Mode => Word_IO.In_File,
  34                       Name => RNG_Unix_Path);
  35       exception
  36          when others =>
  37             Eggog("Could not open RNG at : " & RNG_Unix_Path & "!");
  38       end;
  39    end Init_RNG;
  40    
  41    
  42    -- Fill a FZ from RNG
  43    procedure FZ_Random(RNG : in RNG_Device;
  44                        N   : out FZ) is
  45    begin
  46       begin
  47          -- Fill the destination FZ from this RNG:
  48          for i in N'Range loop
  49             Word_IO.Read(RNG.F, N(i));
  50          end loop;
  51       exception
  52          when others =>
  53             Eggog("Could not read from RNG!");
  54       end;
  55    end FZ_Random;
  56    
  57 end FFA_RNG;