Random number generator (device): Difference between revisions

Content deleted Content added
Nimrod -> Nim
Fortran 2008 version with urandom
Line 163: Line 163:
loop
loop
close-file throw ;</lang>
close-file throw ;</lang>

=={{header|Fortran}}==
Using system /dev/urandom in [[GNU]]/[[Linux]].

<lang fortran>
!-----------------------------------------------------------------------
! Test Linux urandom in Fortran
!-----------------------------------------------------------------------
program urandom_test
use iso_c_binding, only : c_long
implicit none

character(len=*), parameter :: RANDOM_PATH = "/dev/urandom"
integer :: funit, ios
integer(c_long) :: buf

open(newunit=funit, file=RANDOM_PATH, access="stream", form="UNFORMATTED", &
iostat=ios, status="old", action="read")
if ( ios /= 0 ) stop "Error opening file: "//RANDOM_PATH

read(funit) buf

close(funit)

write(*,'(A,I64)') "Integer: ", buf
write(*,'(A,B64)') "Binary: ", buf
write(*,'(A,Z64)') "Hexadecimal: ", buf

end program urandom_test
</lang>

=={{header|Go}}==
=={{header|Go}}==
In the Go library is crypto/rand, a source specified to use dev/urandom on Unix-like systems and the CryptGenRandom API on Windows. Also implemented here is a source using dev/random, if you really want it. On my system it would print a few numbers then hang until I moved the mouse or pressed some keys on the keyboard.
In the Go library is crypto/rand, a source specified to use dev/urandom on Unix-like systems and the CryptGenRandom API on Windows. Also implemented here is a source using dev/random, if you really want it. On my system it would print a few numbers then hang until I moved the mouse or pressed some keys on the keyboard.