[Seaside] Generating a random string
Norbert Hartl
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,
>>
>> atRandom
>> ^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 :)
Norbert
More information about the seaside
mailing list