[Seaside] Generating a random string
norbert at hartl.name
Tue Nov 29 16:34:08 UTC 2011
Am 29.11.2011 um 16:30 schrieb Sven Van Caekenberghe:
> Hey Boris,
> 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) ] ]
how about changing alphabet to
alphabet := Character alphabet asUppercase, ($0 to: $9)
Couldn't resist :)
More information about the seaside