<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <font face="Georgia">Well, less code might be<br>
      <br>
      &nbsp;&nbsp;&nbsp; | alphabet </font><font face="Georgia">aSize</font><font
      face="Georgia"> |<br>
      &nbsp;&nbsp;&nbsp; aSize := 20.<br>
      &nbsp;&nbsp;&nbsp; alphabet := '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.<br>
      &nbsp;&nbsp;&nbsp; (String new: aSize) collect: [ :x | alphabet atRandom].<br>
      <br>
      Cheers,<br>
      Bob<br>
    </font><br>
    On 11/29/11 9:55 AM, Sven Van Caekenberghe wrote:
    <blockquote cite="mid:31A07144-AC2F-467D-B24B-09304E618D67@beta9.be"
      type="cite">
      <pre wrap="">[Pharo]

| size |
size := 32.
String streamContents: [ :stream | 
        size timesRepeat: [ 
                stream nextPut: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ atRandom ] ] 

'TSBY6AHHXF5YYJDNLOFE7P8C4V2OMA8P'

This is a bit slower (due to internal locking), but less code.

Sven

On 29 Nov 2011, at 15:49, Boris Popov, DeepCove Labs wrote:

</pre>
      <blockquote type="cite">
        <pre wrap="">[VisualWorks]

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

'H3H1WNPPEMCNKGHSXK356TA2CA298VNY'

HTH,

-Boris

-----Original Message-----
From: <a class="moz-txt-link-abbreviated" href="mailto:seaside-bounces@lists.squeakfoundation.org">seaside-bounces@lists.squeakfoundation.org</a>
[<a class="moz-txt-link-freetext" href="mailto:seaside-bounces@lists.squeakfoundation.org">mailto:seaside-bounces@lists.squeakfoundation.org</a>] On Behalf Of Aeren
Sent: Tuesday, November 29, 2011 9:44 AM
To: <a class="moz-txt-link-abbreviated" href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a>
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:
<a class="moz-txt-link-freetext" href="http://forum.world.st/Generating-a-random-string-tp4119392p4119392.html">http://forum.world.st/Generating-a-random-string-tp4119392p4119392.html</a>
Sent from the Seaside General mailing list archive at Nabble.com.
_______________________________________________
seaside mailing list
<a class="moz-txt-link-abbreviated" href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a>
<a class="moz-txt-link-freetext" href="http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside">http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside</a>
_______________________________________________
seaside mailing list
<a class="moz-txt-link-abbreviated" href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a>
<a class="moz-txt-link-freetext" href="http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside">http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside</a>
</pre>
      </blockquote>
      <pre wrap="">
_______________________________________________
seaside mailing list
<a class="moz-txt-link-abbreviated" href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a>
<a class="moz-txt-link-freetext" href="http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside">http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside</a>

</pre>
    </blockquote>
  </body>
</html>