[Seaside] Generating a random string
Sven Van Caekenberghe
sven at beta9.be
Tue Nov 29 15:30:32 UTC 2011
On 29 Nov 2011, at 15:57, Boris Popov, DeepCove Labs wrote:
> Someone ended up writing the below for VisualWorks' version of
> #atRandom, so I skipped using it in an example,
> ^self atRandom: Random new
And I thought that VW was such a fast & efficient implementation ?
Anyway, this would be faster (a dedicated, reused Random object, a preallocated String):
| size random alphabet |
size := 32.
random := Random new.
alphabet := '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
String new: 32 streamContents: [ :stream |
size timesRepeat: [
stream nextPut: (alphabet atRandom: random) ] ]
More information about the seaside