[Seaside] Generating a random string

Boris Popov, DeepCove Labs boris at deepcovelabs.com
Tue Nov 29 14:49:54 UTC 2011


[VisualWorks]

alphabet := '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
size := 32.
random := Random new.
String streamContents: [:ws | size timesRepeat: [ws nextPut: (alphabet
atRandom: random)]].

'H3H1WNPPEMCNKGHSXK356TA2CA298VNY'

HTH,

-Boris

-----Original Message-----
From: seaside-bounces at lists.squeakfoundation.org
[mailto:seaside-bounces at lists.squeakfoundation.org] On Behalf Of Aeren
Sent: Tuesday, November 29, 2011 9:44 AM
To: seaside at lists.squeakfoundation.org
Subject: [Seaside] Generating a random string

I'm trying to generate a random string, and i've created a method to do
so based on a few things I found on internet. However, when I try to
generate the string, I receive the error : "Improper store into
indexable object".
The error comes when I try to insert a new random character into my
string.
here is my code.

*randomString:* aSize
	| alphabet word |
	alphabet := '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
	word := String new: aSize.
	1 to: aSize do: [ :position |
		word at: position put: [ alphabet at: ( Random between:
1 and: (alphabet
size) ) ] ].
	
	^word

Any help?

--
View this message in context:
http://forum.world.st/Generating-a-random-string-tp4119392p4119392.html
Sent from the Seaside General mailing list archive at Nabble.com.
_______________________________________________
seaside mailing list
seaside at lists.squeakfoundation.org
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


More information about the seaside mailing list