smalltalk
/
osmo-st-sip
Archived
1
0
Fork 0

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:
Holger Hans Peter Freyther 2013-03-31 20:38:03 +02:00
parent 6559cc6c1c
commit 6878ac5253
2 changed files with 35 additions and 1 deletions

View File

@ -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:

View File

@ -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.
]
]
]