[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

James Gray

3/30/2006 8:39:00 PM

On Mar 30, 2006, at 2:33 PM, Meino Christian Cramer wrote:

> Hi;
>
> I am looking for an algorithm, which spread all 26 letters of the
> alphabet over an array of 26 places randomly. All letters should be
> statistically equally handled.

Well, this is only as good as the random number generator, but it
sure is easy:

>> ("a".."z").sort_by { rand }
=> ["s", "m", "q", "j", "f", "r", "z", "e", "l", "k", "y", "v", "g",
"d", "x", "p", "w", "a", "b", "c", "i", "t", "h", "o", "u", "n"]

Hope that helps.

James Edward Gray II


8 Answers

Meino Christian Cramer

3/30/2006 8:57:00 PM

0

Meino Christian Cramer

3/30/2006 9:12:00 PM

0

James Gray

3/30/2006 9:20:00 PM

0

Can you please title your messages so others know what we are talking
about?

On Mar 30, 2006, at 3:11 PM, Meino Christian Cramer wrote:

> From: James Edward Gray II <james@grayproductions.net>
> Subject: Re:
> Date: Fri, 31 Mar 2006 05:39:15 +0900
>
> Hi,
>
> sorry, me again.
>
> If I want not only "a".."z" but also "A".."Z"

We can just add the Arrays of letters, then randomize:

>> (("a".."z").to_a + ("A".."Z").to_a).sort_by { rand }
=> ["h", "j", "m", "x", "z", "O", "n", "r", "T", "F", "N", "k", "U",
"a", "W", "p", "V", "E", "L", "A", "v", "D", "J", "P", "y", "C", "g",
"u", "S", "i", "w", "q", "l", "K", "c", "B", "Z", "s", "t", "Y", "R",
"e", "d", "o", "M", "I", "X", "f", "b", "G", "Q", "H"]

Hope that helps.

James Edward Gray II


Daniel Harple

3/30/2006 9:22:00 PM

0

On Mar 30, 2006, at 11:11 PM, Meino Christian Cramer wrote:

> I want not only "a".."z" but also "A".."Z"

Try:

(("a".."z").to_a + ("A".."Z").to_a).sort_by { rand }

-- Daniel


baumanj

3/30/2006 9:22:00 PM

0

Not quite as elegant, but this should work:

(('a'..'z').to_a + ('A'..'Z').to_a).sort_by { rand }

Meino Christian Cramer wrote:
> From: James Edward Gray II <james@grayproductions.net>
> Subject: Re:
> Date: Fri, 31 Mar 2006 05:39:15 +0900
>
> Hi,
>
> sorry, me again.
>
> If I want not only "a".."z" but also "A".."Z" I thought (from the
> logical point of view...) that
>
> >> a=("A".."z").sort_by { rand }
>
> would work, but it gaves me:
>
> >> a
> => ["P", "D", "Q", "N", "H", "A", "M", "X", "G", "C",
> "E", "L", "I", "S", "B", "J", "F", "Y", "T", "Z", "V", "K", "O", "U", "R", "W"]
>
> which isn't exactly, what I have exspected....
>
> Unfortunately
>
> a=("A".."Z").sort_by { rand } + ("a".."z").sort_by { rand }
>
> would first randomize A->Z and then a->z and dont mix both.
>
> Or am I not thinking too straight forward again ;) ?
>
> Keep hacking!
> mcc
>
>
>
> > On Mar 30, 2006, at 2:33 PM, Meino Christian Cramer wrote:
> >
> > > Hi;
> > >
> > > I am looking for an algorithm, which spread all 26 letters of the
> > > alphabet over an array of 26 places randomly. All letters should be
> > > statistically equally handled.
> >
> > Well, this is only as good as the random number generator, but it
> > sure is easy:
> >
> > >> ("a".."z").sort_by { rand }
> > => ["s", "m", "q", "j", "f", "r", "z", "e", "l", "k", "y", "v", "g",
> > "d", "x", "p", "w", "a", "b", "c", "i", "t", "h", "o", "u", "n"]
> >
> > Hope that helps.
> >
> > James Edward Gray II
> >

Gary Wright

3/30/2006 9:22:00 PM

0


On Mar 30, 2006, at 4:11 PM, Meino Christian Cramer wrote:
> If I want not only "a".."z" but also "A".."Z" I thought (from the
> logical point of view...) that
>
>>> a=("A".."z").sort_by { rand }

a = (('a'..'z').to_a + ('A'..'Z').to_a).sort_by { rand }

Gary Wright





Timothy Bennett

3/30/2006 9:23:00 PM

0

a = ("A".."Z" + "a".."z").sort_by { rand }

Tim

On Mar 30, 2006, at 1:11 PM, Meino Christian Cramer wrote:

> From: James Edward Gray II <james@grayproductions.net>
> Subject: Re:
> Date: Fri, 31 Mar 2006 05:39:15 +0900
>
> Hi,
>
> sorry, me again.
>
> If I want not only "a".."z" but also "A".."Z" I thought (from the
> logical point of view...) that
>
>>> a=("A".."z").sort_by { rand }
>
> would work, but it gaves me:
>
>>> a
> => ["P", "D", "Q", "N", "H", "A", "M", "X", "G", "C",
> "E", "L", "I", "S", "B", "J", "F", "Y", "T", "Z", "V", "K",
> "O", "U", "R", "W"]
>
> which isn't exactly, what I have exspected....
>
> Unfortunately
>
> a=("A".."Z").sort_by { rand } + ("a".."z").sort_by { rand }
>
> would first randomize A->Z and then a->z and dont mix both.
>
> Or am I not thinking too straight forward again ;) ?
>
> Keep hacking!
> mcc
>
>
>
>> On Mar 30, 2006, at 2:33 PM, Meino Christian Cramer wrote:
>>
>>> Hi;
>>>
>>> I am looking for an algorithm, which spread all 26 letters of the
>>> alphabet over an array of 26 places randomly. All letters should be
>>> statistically equally handled.
>>
>> Well, this is only as good as the random number generator, but it
>> sure is easy:
>>
>>>> ("a".."z").sort_by { rand }
>> => ["s", "m", "q", "j", "f", "r", "z", "e", "l", "k", "y", "v", "g",
>> "d", "x", "p", "w", "a", "b", "c", "i", "t", "h", "o", "u", "n"]
>>
>> Hope that helps.
>>
>> James Edward Gray II
>>
>



Meino Christian Cramer

3/31/2006 4:17:00 AM

0