author | Claus Gittinger <cg@exept.de> |
Tue, 25 Jun 2019 14:28:51 +0200 | |
changeset 5050 | 44fa8672d102 |
parent 4602 | b74d89eed13a |
child 5176 | 55374cc71a4b |
permissions | -rw-r--r-- |
4602 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1925 | 3 |
" |
4 |
COPYRIGHT (c) 2007 by eXept Software AG |
|
5 |
All Rights Reserved |
|
6 |
||
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
1606 | 14 |
"{ Package: 'stx:libbasic2' }" |
15 |
||
3632 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
3193 | 18 |
Random subclass:#RandomGenerator |
3854 | 19 |
instanceVariableNames:'' |
4250 | 20 |
classVariableNames:'HasOSRandom RandFile RandomDevicePathes SharedRandomGenerator' |
3854 | 21 |
poolDictionaries:'' |
4597 | 22 |
category:'Magnitude-Numbers-Random' |
1606 | 23 |
! |
24 |
||
25 |
!RandomGenerator class methodsFor:'documentation'! |
|
26 |
||
1925 | 27 |
copyright |
28 |
" |
|
29 |
COPYRIGHT (c) 2007 by eXept Software AG |
|
30 |
All Rights Reserved |
|
31 |
||
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
40 |
||
1606 | 41 |
documentation |
42 |
" |
|
3777 | 43 |
This is a Random number generator, |
44 |
which uses either a OS random number generator or /dev/urandom, |
|
45 |
or an ST/X internal random number generator. |
|
46 |
||
4482 | 47 |
Warning: |
48 |
this generator should not be used for cryptographic work |
|
3777 | 49 |
UNLESS: |
3351
a9ae920e4a1f
comment/format in: #documentation
Claus Gittinger <cg@exept.de>
parents:
3339
diff
changeset
|
50 |
1) you are running on linux, solaris or osx, |
a9ae920e4a1f
comment/format in: #documentation
Claus Gittinger <cg@exept.de>
parents:
3339
diff
changeset
|
51 |
2) you have a working /dev/urandom. |
a9ae920e4a1f
comment/format in: #documentation
Claus Gittinger <cg@exept.de>
parents:
3339
diff
changeset
|
52 |
3) you can trust your /dev/urandom (I don't really know if any/all of them are good) |
a9ae920e4a1f
comment/format in: #documentation
Claus Gittinger <cg@exept.de>
parents:
3339
diff
changeset
|
53 |
|
4482 | 54 |
It is a facade one one of the other random generators, |
55 |
and will choose (in decreasing priority) the first available generator from the following: |
|
56 |
||
57 |
- OS random system call |
|
58 |
- /dev/urandom |
|
59 |
- rc4-based random (if present) |
|
60 |
- regular (untrusted) random as fallback |
|
61 |
||
1606 | 62 |
[author:] |
63 |
Stefan Vogel |
|
64 |
||
65 |
[see also:] |
|
3391 | 66 |
http://www0.cs.ucl.ac.uk/staff/d.jones/GoodPracticeRNG.pdf |
1606 | 67 |
Random HashRandom Rc4Stream |
68 |
||
69 |
[instance variables:] |
|
70 |
||
71 |
[class variables:] |
|
3777 | 72 |
HasOSRandom true if the operatingSystem supports random numbers |
73 |
RandFile (if HasOSRandom is false and non-nil) the FileStream (/dev/random), |
|
74 |
we get random numbers from |
|
1606 | 75 |
" |
76 |
! ! |
|
77 |
||
78 |
!RandomGenerator class methodsFor:'initialization'! |
|
79 |
||
80 |
initialize |
|
81 |
"want to be informed when returning from snapshot" |
|
82 |
||
83 |
ObjectMemory addDependent:self. |
|
84 |
||
85 |
||
86 |
! |
|
87 |
||
88 |
openRandFile |
|
89 |
"try to open a random device" |
|
90 |
||
91 |
|randDevName| |
|
92 |
||
3777 | 93 |
RandFile notNil ifTrue:[ |
1606 | 94 |
RandFile close. |
3777 | 95 |
RandFile := nil. |
1606 | 96 |
]. |
97 |
||
98 |
randDevName := self randPath. |
|
99 |
randDevName notNil ifTrue:[ |
|
100 |
randDevName := randDevName asFilename. |
|
101 |
randDevName isReadable ifTrue:[ |
|
3777 | 102 |
RandFile := randDevName readStream. |
1606 | 103 |
]. |
104 |
]. |
|
105 |
! ! |
|
106 |
||
107 |
!RandomGenerator class methodsFor:'instance creation'! |
|
108 |
||
109 |
new |
|
110 |
"return a new random number generator. |
|
4250 | 111 |
Try to get system random numbers from OS (e.g. in LINUX) |
112 |
or device urandom (e.g. in Linux, OSX). |
|
4025 | 113 |
If no system random numbers are available, fall back to |
4250 | 114 |
a cryptographic secure PRNG (like RC4Random, part of the extra libcrypt package). |
1606 | 115 |
As last resort fallback to the cryptographic insecure linear builtin PRNG" |
116 |
||
2439
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
117 |
|result| |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
118 |
|
3193 | 119 |
SharedRandomGenerator notNil ifTrue:[ |
4602 | 120 |
"each time, we do a new, add some entropy to the SharedRandomGenerator" |
3193 | 121 |
SharedRandomGenerator addEntropy:OperatingSystem getMicrosecondTime. |
122 |
^ SharedRandomGenerator. |
|
2432 | 123 |
]. |
124 |
||
3854 | 125 |
HasOSRandom isNil ifTrue:[ |
3777 | 126 |
"/ see if there is an OS or CPU-random generator |
127 |
[ |
|
128 |
"fetch a random byte - and check if the OS generator works" |
|
129 |
result := OperatingSystem randomBytesInto:1. |
|
130 |
] on:PrimitiveFailure do:[:ex| ]. |
|
131 |
HasOSRandom := result notNil. |
|
132 |
]. |
|
4025 | 133 |
|
3777 | 134 |
HasOSRandom ifTrue:[ |
2439
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
135 |
"OperatingSystem knows how to get random bytes" |
3193 | 136 |
SharedRandomGenerator := self basicNew. |
3203 | 137 |
^ SharedRandomGenerator. |
3777 | 138 |
]. |
4025 | 139 |
|
3777 | 140 |
RandFile isNil ifTrue:[ |
141 |
self openRandFile. |
|
142 |
]. |
|
143 |
RandFile notNil ifTrue:[ |
|
144 |
SharedRandomGenerator := self basicNew. |
|
145 |
^ SharedRandomGenerator. |
|
1606 | 146 |
]. |
147 |
||
4025 | 148 |
"/ fallback |
2432 | 149 |
Rc4Cipher notNil ifTrue:[ |
3193 | 150 |
SharedRandomGenerator := Rc4Cipher random. |
151 |
^ SharedRandomGenerator. |
|
2432 | 152 |
]. |
153 |
||
4025 | 154 |
"/ last fallback - not very good |
3193 | 155 |
SharedRandomGenerator := Random sharedGenerator. |
156 |
^ SharedRandomGenerator. |
|
1606 | 157 |
! ! |
158 |
||
2432 | 159 |
!RandomGenerator class methodsFor:'adding entropy'! |
160 |
||
161 |
addEntropy:entropyBytes |
|
3193 | 162 |
SharedRandomGenerator notNil ifTrue:[ |
163 |
SharedRandomGenerator addEntropy:entropyBytes |
|
2432 | 164 |
]. |
165 |
! ! |
|
166 |
||
1606 | 167 |
!RandomGenerator class methodsFor:'change & update'! |
168 |
||
169 |
update:something with:aParameter from:changedObject |
|
170 |
"handle image restarts and flush any device resource handles" |
|
171 |
||
3777 | 172 |
(changedObject == ObjectMemory) ifTrue:[ |
173 |
(something == #returnFromSnapshot) ifTrue:[ |
|
174 |
SharedRandomGenerator notNil ifTrue:[ |
|
175 |
SharedRandomGenerator := nil. |
|
176 |
HasOSRandom := RandFile := nil. |
|
4602 | 177 |
self new. "/ opens a new SharedRandomGenerator |
3777 | 178 |
] |
179 |
] |
|
1606 | 180 |
]. |
181 |
! ! |
|
182 |
||
183 |
!RandomGenerator class methodsFor:'queries'! |
|
184 |
||
185 |
randPath |
|
186 |
"path to a file/device that is a source or random numbers" |
|
187 |
||
4041 | 188 |
|pathsOrNil| |
3777 | 189 |
|
4041 | 190 |
pathsOrNil := self randomDevicePathes. |
191 |
pathsOrNil notNil ifTrue:[ |
|
192 |
pathsOrNil do:[:triedRandom | |
|
3777 | 193 |
triedRandom asFilename exists ifTrue:[ |
194 |
^ triedRandom |
|
195 |
] |
|
4041 | 196 |
]. |
3777 | 197 |
]. |
1606 | 198 |
^ nil. |
3777 | 199 |
! |
200 |
||
201 |
randomDevicePathes |
|
4250 | 202 |
"paths to look for OS sources of random numbers. |
203 |
Can be configured at early startup to use something special |
|
204 |
(i.e. a special hardware random device) |
|
205 |
If never set, the defaults /dev/random, /dev/urandom are used" |
|
3777 | 206 |
|
207 |
RandomDevicePathes notNil ifTrue:[^ RandomDevicePathes]. |
|
208 |
OperatingSystem isUNIXlike ifTrue:[ |
|
209 |
^ #( '/dev/urandom' '/dev/random' ) |
|
210 |
]. |
|
211 |
^ nil. |
|
212 |
! |
|
213 |
||
4250 | 214 |
randomDevicePathes:aCollectionOfPathesOrNil |
4041 | 215 |
"configurable paths to look for OS sources of random numbers. |
4250 | 216 |
(can be set during early startup in an rc-file). |
217 |
If never set, the defaults /dev/random, /dev/urandom are used" |
|
3777 | 218 |
|
4250 | 219 |
RandomDevicePathes := aCollectionOfPathesOrNil. |
1606 | 220 |
! ! |
221 |
||
2439
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
222 |
!RandomGenerator methodsFor:'basic reading'! |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
223 |
|
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
224 |
nextByte |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
225 |
"get the next random byte" |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
226 |
|
3777 | 227 |
HasOSRandom == true ifTrue:[ |
2439
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
228 |
^ OperatingSystem randomBytesInto:1. |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
229 |
]. |
3632 | 230 |
RandFile isOpen ifFalse:[ |
231 |
self class openRandFile. |
|
232 |
]. |
|
2439
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
233 |
^ RandFile nextByte |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
234 |
|
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
235 |
" |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
236 |
RandomGenerator new nextByte |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
237 |
" |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
238 |
|
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
239 |
" |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
240 |
Distribution should be equal: |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
241 |
|
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
242 |
|r bag| |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
243 |
r := RandomGenerator new. |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
244 |
bag := Bag new. |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
245 |
1000000 timesRepeat:[ |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
246 |
bag add:(r nextByte). |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
247 |
]. |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
248 |
bag. |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
249 |
Transcript showCR:bag contents |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
250 |
" |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
251 |
|
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
252 |
"Created: / 11.11.1999 / 09:25:39 / stefan" |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
253 |
! |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
254 |
|
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
255 |
nextBytes:cnt |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
256 |
"get the next cnt random bytes" |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
257 |
|
3777 | 258 |
HasOSRandom == true ifTrue:[ |
2439
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
259 |
^ OperatingSystem randomBytesInto:(ByteArray new:cnt). |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
260 |
]. |
3632 | 261 |
RandFile isOpen ifFalse:[ |
262 |
self class openRandFile. |
|
263 |
]. |
|
2439
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
264 |
^ RandFile nextBytes:cnt. |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
265 |
|
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
266 |
" |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
267 |
RandomGenerator new nextBytes:4 |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
268 |
" |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
269 |
|
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
270 |
"Created: / 11.11.1999 / 09:25:39 / stefan" |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
271 |
"Modified: / 11.11.1999 / 09:52:26 / stefan" |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
272 |
! ! |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
273 |
|
1606 | 274 |
!RandomGenerator methodsFor:'reading'! |
275 |
||
4602 | 276 |
maxInteger |
277 |
"return the max integral random number returned by nextInteger" |
|
278 |
||
279 |
SmallInteger maxBytes == 8 ifTrue:[ |
|
280 |
^ 16r3FFFFFFFFFFFFFFF |
|
281 |
] ifFalse:[ |
|
282 |
^ 16r3FFFFFFF |
|
283 |
]. |
|
284 |
||
285 |
" |
|
286 |
RandomGenerator new maxInteger. |
|
287 |
" |
|
288 |
||
289 |
"Modified: / 11.11.1999 / 10:08:10 / stefan" |
|
290 |
! |
|
291 |
||
1606 | 292 |
next |
293 |
"return the next random number in the range 0..1" |
|
294 |
||
3751 | 295 |
^ self nextInteger / Float maxSmallInteger |
1606 | 296 |
|
297 |
" |
|
298 |
|r| |
|
299 |
r := RandomGenerator new. |
|
300 |
Transcript showCR:r next. |
|
301 |
Transcript showCR:r next. |
|
302 |
Transcript showCR:r next. |
|
303 |
Transcript showCR:r next. |
|
304 |
" |
|
305 |
||
306 |
"Modified: / 11.11.1999 / 10:31:35 / stefan" |
|
307 |
! |
|
308 |
||
309 |
nextBoolean |
|
310 |
"return true or false by random" |
|
311 |
||
312 |
^ self nextByte <= 127 |
|
313 |
||
314 |
" |
|
315 |
|r| |
|
316 |
r := RandomGenerator new. |
|
317 |
Transcript showCR:r nextBoolean. |
|
318 |
Transcript showCR:r nextBoolean. |
|
319 |
Transcript showCR:r nextBoolean. |
|
320 |
Transcript showCR:r nextBoolean. |
|
321 |
" |
|
322 |
||
323 |
" |
|
2439
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
324 |
Distribution should approach 50/50: |
8ef4ad63fb9b
comment/format in: #nextBoolean
Stefan Vogel <sv@exept.de>
parents:
2438
diff
changeset
|
325 |
|
1606 | 326 |
|r bag| |
327 |
r := RandomGenerator new. |
|
328 |
bag := Bag new. |
|
329 |
1000000 timesRepeat:[ |
|
330 |
bag add:(r nextBoolean). |
|
331 |
]. |
|
332 |
Transcript showCR:bag contents |
|
333 |
" |
|
334 |
||
335 |
"Created: / 11.11.1999 / 09:25:39 / stefan" |
|
336 |
"Modified: / 12.11.1999 / 17:22:01 / stefan" |
|
337 |
! |
|
338 |
||
3751 | 339 |
nextCharacters:count |
340 |
"get the next count printable characters. |
|
341 |
We answer printable characters in the ascii range (codepoints 32 - 126)" |
|
1640 | 342 |
|
3751 | 343 |
|bytes string cnt "{ Class:SmallInteger }"| |
1640 | 344 |
|
3751 | 345 |
cnt := count. |
1640 | 346 |
bytes := self nextBytes:cnt. |
347 |
string := String new:cnt. |
|
348 |
||
3751 | 349 |
1 to:cnt do:[:eachIndex| |
350 |
string at:eachIndex put:(Character value:((bytes at:eachIndex) \\ 94 + 32)). |
|
1640 | 351 |
]. |
352 |
||
353 |
^ string |
|
354 |
||
355 |
" |
|
356 |
RandomGenerator new nextCharacters:8 |
|
357 |
" |
|
358 |
! |
|
359 |
||
3632 | 360 |
nextInteger |
361 |
"return the next integral random number, |
|
3751 | 362 |
in the range 0 .. 16r3FFFFFFF (32-bit) |
363 |
or 0 .. 16r3FFFFFFFFFFFFFFF (64-bit)." |
|
3632 | 364 |
|
3751 | 365 |
|res intSize| |
366 |
||
367 |
intSize := SmallInteger maxBytes. |
|
3632 | 368 |
|
3777 | 369 |
HasOSRandom == true ifTrue:[ |
3751 | 370 |
^ OperatingSystem randomBytesInto:intSize. |
3632 | 371 |
]. |
372 |
||
3751 | 373 |
res := self nextBytes:intSize. |
374 |
res at:intSize put:((res at:intSize) bitAnd:16r3F). |
|
375 |
^ res asIntegerMSB:false. |
|
3632 | 376 |
|
377 |
||
378 |
" |
|
379 |
|r| |
|
380 |
r := RandomGenerator new. |
|
381 |
Transcript showCR:r nextInteger. |
|
382 |
Transcript showCR:r nextInteger. |
|
383 |
Transcript showCR:r nextInteger. |
|
384 |
Transcript showCR:r nextInteger. |
|
385 |
" |
|
386 |
||
387 |
"Modified: / 11.11.1999 / 10:08:10 / stefan" |
|
388 |
! |
|
389 |
||
3751 | 390 |
nextLettersOrDigits:count |
391 |
"get the next count printable letters or digits [0-9A-Za-z]." |
|
392 |
||
393 |
|bytes string cnt "{ Class:SmallInteger }"| |
|
394 |
||
395 |
cnt := count. |
|
396 |
bytes := self nextBytes:cnt. |
|
397 |
string := String new:cnt. |
|
398 |
||
399 |
1 to:cnt do:[:eachIndex| |
|
400 |
string |
|
401 |
at:eachIndex |
|
402 |
put:('1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' at:((bytes at:eachIndex) \\ 62 + 1)). |
|
403 |
]. |
|
404 |
||
405 |
^ string |
|
406 |
||
407 |
" |
|
408 |
RandomGenerator new nextLettersOrDigits:40 |
|
409 |
" |
|
1606 | 410 |
! ! |
411 |
||
412 |
!RandomGenerator methodsFor:'writing'! |
|
413 |
||
414 |
nextPut:something |
|
415 |
"change the random pool by feeding in something. |
|
416 |
Something should be some unpredictable, random event. |
|
417 |
Ignored here" |
|
418 |
||
419 |
||
420 |
! |
|
421 |
||
422 |
nextPutAll:something |
|
423 |
"change the random pool by feeding in something. |
|
424 |
Something should be some unpredictable, random event. |
|
425 |
Ignored here" |
|
426 |
||
427 |
! ! |
|
428 |
||
429 |
!RandomGenerator class methodsFor:'documentation'! |
|
430 |
||
431 |
version |
|
3632 | 432 |
^ '$Header$' |
2432 | 433 |
! |
434 |
||
435 |
version_CVS |
|
3632 | 436 |
^ '$Header$' |
1606 | 437 |
! ! |
438 |
||
3025 | 439 |
|
1606 | 440 |
RandomGenerator initialize! |