Random number generator (device): Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 101:
Ada.Text_IO.Put_Line ("Number:" & Integer'Image (Number));
end Random;</lang>
 
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
Line 312 ⟶ 313:
 
</lang>
 
=={{header|Batch File}}==
The dynamic environmental variable <code>%random%</code> contains a number between 0 and 32767.
Line 486 ⟶ 488:
(with-open-file (s "/dev/random" :element-type '(unsigned-byte 32))
(read-byte s)))</lang>
 
 
=={{header|D}}==
Line 573 ⟶ 574:
 
Here's an example of the use of the latter:
 
=={{header|FreeBASIC}}==
FreeBASIC can in theory use any C library to produce pseudo-random numbers including those which are partly device based.
Line 641 ⟶ 643:
1152610574
714616658</pre>
 
=={{header|Haskell}}==
{{libheader|Entropy}}
{{Works with|GHC|7.4.1}}
<lang haskell>#!/usr/bin/env runhaskell
 
import System.Entropy
import Data.Binary.Get
import qualified Data.ByteString.Lazy as B
 
main = do
bytes <- getEntropy 4
print (runGet getWord32be $ B.fromChunks [bytes])</lang>
 
=={{header|Icon}} and {{header|Unicon}}==
Line 711 ⟶ 726:
 
Notice that the program automatically adjusts the precision based on the length of the hexadecimal numbers presented. Since jq uses IEEE 754 64-bit arithmetic, specifying a larger value to `fold`, such as 10, will produce more precise results.
 
=={{header|Julia}}==
{{works with|Linux}}
Line 735 ⟶ 751:
A hardware random number is: 986109744
</pre>
 
=={{header|Haskell}}==
{{libheader|Entropy}}
{{Works with|GHC|7.4.1}}
<lang haskell>#!/usr/bin/env runhaskell
 
import System.Entropy
import Data.Binary.Get
import qualified Data.ByteString.Lazy as B
 
main = do
bytes <- getEntropy 4
print (runGet getWord32be $ B.fromChunks [bytes])</lang>
 
=={{header|Kotlin}}==
Line 961 ⟶ 964:
print "$_\n" for read_random(10);</lang>
Whether /dev/urandom is good enough for cryptographic work is debated, though on most UNIX systems it is at least as good as the Win32 Crypto API.
 
=={{header|Perl 6}}==
{{Works with|rakudo|2016-11}}
 
A lazy list of random numbers:
 
<lang perl6>use experimental :pack;
my $UR = open("/dev/urandom", :bin) orelse .die;
my @random-spigot = $UR.read(1024).unpack("L*") ... *;
 
.say for @random-spigot[^10];</lang>
{{out}}
<pre>1431009271
1702240522
670020272
588612037
1864913839
2155430433
1690056587
385405103
2366495746
692037942</pre>
 
=={{header|Phix}}==
Line 1,119 ⟶ 1,100:
Uses math module:
<lang ProDOS>printline -random- </lang>
 
=={{header|PureBasic}}==
PureBasic has the source for the random data is the "/dev/urandom" device on Linux or Mac OSX and the "Microsoft Cryptography API" on Windows.
Line 1,138 ⟶ 1,120:
(λ(i) (integer-bytes->integer (read-bytes 4 i) #f)))
</lang>
 
=={{header|Perl 6Raku}}==
(formerly Perl 6)
{{Works with|rakudo|2016-11}}
 
A lazy list of random numbers:
 
<lang perl6>use experimental :pack;
my $UR = open("/dev/urandom", :bin) orelse .die;
my @random-spigot = $UR.read(1024).unpack("L*") ... *;
 
.say for @random-spigot[^10];</lang>
{{out}}
<pre>1431009271
1702240522
670020272
588612037
1864913839
2155430433
1690056587
385405103
2366495746
692037942</pre>
 
=={{header|REXX}}==
Line 1,219 ⟶ 1,224:
}
}</lang>
 
=={{header|Sidef}}==
<lang ruby>func urandom() {
10,333

edits