[Seaside] Generating a random string

Louis LaBrunda Lou at Keystone-Software.com
Tue Nov 29 15:11:35 UTC 2011


Hi Aeren,

You have two problems with your code.  The first looks like a typo.  The
"[" after put: should be a "(" and its matching "]" should be a ")".  As
is, the code is trying to store a block where a character should go.

The second problem is with your use of Random.  There is no #between:and:
class or instance method of Random.  You need to create a new instance of
Random, something like:

	random := Random seed: 100000.

You should look up what a good value for the seed should be, I just used
100000 as an example.

Then you should use:

(random nextInt: (alphabet size))

to get your next random character.

I hope this helps and good luck.

Lou

>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?
-----------------------------------------------------------
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:Lou at Keystone-Software.com http://www.Keystone-Software.com



More information about the seaside mailing list