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)


/* NetRexx */
options replace format comments java crossref savelog symbols binary
 
import java.math.BigInteger
 
randomDevNameFile = File
randomDevNameList = ['/dev/random', '/dev/urandom'] -- list of random data source devices
randomDevIStream = InputStream
do
  loop dn = 0 to randomDevNameList.length - 1
    randomDevNameFile = File(randomDevNameList[dn])
    if randomDevNameFile.exists() then leave dn -- We're done! Use this device
    randomDevNameFile = null -- ensure we don't use a non-existant device
    end dn
  if randomDevNameFile == null then signal FileNotFoundException('Cannot locate a random data source device on this system')
 
  -- read 8 bytes from the random data source device, convert it into a BigInteger then display the result
  randomBytes = byte[8]
  randomDevIStream = BufferedInputStream(FileInputStream(randomDevNameFile))
  randomDevIStream.read(randomBytes, 0, randomBytes.length)
  randomDevIStream.close()
  randomNum = BigInteger(randomBytes)
  say Rexx(randomNum.longValue()).right(24) '0x'Rexx(Long.toHexString(randomNum.longValue())).right(16, 0)
catch ex = IOException
  ex.printStackTrace()
end
return
 
/*
To run the program in a loop 10 times from a bash shell prompt use:
for ((i=0; i<10; ++i)); do java <program_name>; done # Shell loop to run the command 10 times
*/
 