# HG changeset patch # User Claus Gittinger # Date 1520003700 -3600 # Node ID 169bd0f282fb2a7d230a20c4858f99d2be0f11ef # Parent 409af0c80e0996c53586985378c0a5869872955f #FEATURE by cg class: Random added: #nextBytesNonZero: diff -r 409af0c80e09 -r 169bd0f282fb Random.st --- a/Random.st Fri Mar 02 14:15:56 2018 +0100 +++ b/Random.st Fri Mar 02 16:15:00 2018 +0100 @@ -1,3 +1,5 @@ +"{ Encoding: utf8 }" + " ====================================================================== | @@ -549,6 +551,33 @@ "Modified: 1.4.1997 / 22:42:53 / cg" ! +nextBytesNonZero:count + "return count random bytes, none of which is zero (i.e. 1..16rFF each)" + + |res cnt "{Class: SmallInteger}"| + + cnt := count. + res := ByteArray uninitializedNew:cnt. + + 1 to:cnt do:[:i| + |nextNonZero| + + [ + self step. + (nextNonZero := seed bitAnd:16rFF) == 0 + ] whileTrue. + res at:i put:nextNonZero. + ]. + + ^ res + + " + Transcript showCR:(Random new nextBytesNonZero:20). + " + + "Modified: 1.4.1997 / 22:42:53 / cg" +! + nextCharacters:count "get the next cnt printable characters. We answer printable characters in the ascii range (codepoints 32 - 126)"