Random.st
changeset 3750 54c47e28047d
parent 3675 058f3f83eae0
child 3776 d1412e4f5779
--- a/Random.st	Sat Mar 12 23:27:01 2016 +0100
+++ b/Random.st	Mon Mar 14 18:42:00 2016 +0100
@@ -258,6 +258,22 @@
 
     "Created: 21.8.1997 / 18:07:00 / cg"
     "Modified: 21.8.1997 / 18:08:56 / cg"
+!
+
+nextLettersOrDigits:count
+    "get the next count printable letters or digits [0-9A-Za-z]."
+
+    ^ self sharedGenerator nextLettersOrDigits:count
+
+    "
+     Transcript showCR:(Random nextLettersOrDigits:10).
+     Transcript showCR:(Random nextLettersOrDigits:10).
+     Transcript showCR:(Random nextLettersOrDigits:10).
+     Transcript showCR:(Random nextLettersOrDigits:10).
+    "
+
+    "Created: 21.8.1997 / 18:07:00 / cg"
+    "Modified: 21.8.1997 / 18:08:56 / cg"
 ! !
 
 !Random class methodsFor:'seeding'!
@@ -533,15 +549,16 @@
 
 nextCharacters:count
     "get the next cnt printable characters.
-     We answer characters in the ascii range (codepoints 32 - 127)"
+     We answer printable characters in the ascii range (codepoints 32 - 126)"
 
-    |res|
+    |res cnt "{ Class:SmallInteger }"|
 
-    res := String uninitializedNew:count.
+    cnt := count.
+    res := String uninitializedNew:cnt.
 
-    1 to:count do:[:i|
+    1 to:cnt do:[:i|
         self step.
-        res at:i put:(Character value:(seed \\ 95 + 32)).
+        res at:i put:(Character value:(seed \\ 94 + 32)).
     ].
 
     ^ res
@@ -660,6 +677,28 @@
          self assert:((r nextIntegerBetween:1 and:3) between:1 and:3).
      ].
     "
+!
+
+nextLettersOrDigits:count
+    "get the next count printable letters or digits [0-9A-Za-z]."
+
+    |res cnt "{ Class:SmallInteger }"|
+
+    cnt := count.
+    res := String uninitializedNew:cnt.
+
+    1 to:cnt do:[:i|
+        self step.
+        res 
+            at:i 
+            put:('1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' at:(seed \\ 62 + 1)).
+    ].
+
+    ^ res
+
+    "
+      Random new nextLettersOrDigits:40
+    "
 ! !
 
 !Random methodsFor:'blocked methods'!