Random number generator (device): Difference between revisions
Content added Content deleted
(→Tcl: Added implementation) |
(→{{header|PicoLisp}}: Added PureBasic) |
||
Line 6: | Line 6: | ||
<lang PicoLisp>: (in "/dev/urandom" (rd 4)) |
<lang PicoLisp>: (in "/dev/urandom" (rd 4)) |
||
-> 2917110327</lang> |
-> 2917110327</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. |
|||
<lang PureBasic>If OpenCryptRandom() |
|||
MyRandom = CryptRandom(#MAXLONG) |
|||
CloseCryptRandom() |
|||
EndIf</lang> |
|||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
Revision as of 16:07, 11 January 2011
Random number generator (device) is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
If your system has a means to generate random numbers involving not only a software algorithm (like the /dev/random devices in Unix), show how to obtain a random 32-bit number from that mechanism.
PicoLisp
<lang PicoLisp>: (in "/dev/urandom" (rd 4)) -> 2917110327</lang>
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. <lang PureBasic>If OpenCryptRandom()
MyRandom = CryptRandom(#MAXLONG) CloseCryptRandom()
EndIf</lang>
Tcl
<lang tcl>package require Tcl 8.5
- Allow override of device name
proc systemRandomInteger Template:Device "/dev/urandom" {
set f [open $device "rb"] binary scan [read $f 4] "I" x close $f return $x
}</lang> Usage: <lang tcl>% puts [systemRandomInteger] 636131349</lang>