Task

If your system has a means to generate random numbers involving not only a software algorithm   (like the /dev/urandom devices in Unix),   then:

show how to obtain a random 32-bit number from that mechanism.

Related task
 Random_number_generator_(included)


:- module random_number_device.
:- interface.
 
:- import_module io.
:- pred main(io::di, io::uo) is det.
 
:- implementation.
:- import_module maybe, random, random.system_rng, require.
 
main(!IO) :-
   open_system_rng(MaybeRNG, !IO),
   (
      MaybeRNG = ok(RNG),
      random.generate_uint32(RNG, U32, !IO),
      io.print_line(U32, !IO),
      close_system_rng(RNG, !IO)
   ;
      MaybeRNG = error(ErrorMsg),
      io.stderr_stream(Stderr, !IO),
      io.print_line(Stderr, ErrorMsg, !IO),
      io.set_exit_status(1, !IO)
   ).