pharo: Povide a pharo specific way to access the /dev/urandom device
We need to start with a FileStream and call binary on it. This appears to be doing the tick.
This commit is contained in:
parent
6559cc6c1c
commit
6878ac5253
2
Makefile
2
Makefile
|
@ -46,7 +46,7 @@ CALLAGENT = \
|
|||
callagent/Tests.st
|
||||
|
||||
PHARO_COMPAT = pharo-porting/compat_for_pharo.st
|
||||
PHARO_CHANGES =
|
||||
PHARO_CHANGES = pharo-porting/changes_for_pharo.st
|
||||
|
||||
|
||||
all:
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
|
||||
SIPURandom class extend [
|
||||
nextByte [
|
||||
<category: 'random'>
|
||||
| file |
|
||||
"Pharo has a weird kind of stream support"
|
||||
|
||||
file := (FileStream readOnlyFileNamed: '/dev/urandom')
|
||||
binary; yourself.
|
||||
[
|
||||
^ file next value.
|
||||
] ensure: [
|
||||
file close.
|
||||
]
|
||||
]
|
||||
|
||||
nextInt [
|
||||
<category: 'random'>
|
||||
| file |
|
||||
file := (FileStream readOnlyFileNamed: '/dev/urandom')
|
||||
binary; yourself.
|
||||
[
|
||||
| data |
|
||||
data := ByteArray new: 4.
|
||||
1 to: data size do: [:each |
|
||||
data at: each put: file next value.
|
||||
].
|
||||
|
||||
^ data uintAt: 1
|
||||
] ensure: [
|
||||
file close.
|
||||
]
|
||||
]
|
||||
]
|
Reference in New Issue