(no subject)

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.

Thank you very much for any helpful reply ! :slight_smile:

Keep hacking!
mcc

On Mar 30, 2006, at 2:33 PM, Meino Christian C. 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 G. II

From: James Edward G. II [email protected]
Subject: Re:
Date: Fri, 31 Mar 2006 05:39:15 +0900

Hi James,

again the ruby-effect: The way to code things in ruby is just too
straight forward and (only meant positively) simple.

Again, I was thinking way too complex…with no result at all.

Thanks a lot! :slight_smile:

Have a nice time!
mcc

From: James Edward G. II [email protected]
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 :wink: ?

Keep hacking!
mcc

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

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

From: James Edward G. II [email protected]
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 G. II

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

I want not only β€œaβ€β€¦β€œz” but also β€œAβ€β€¦β€œZ”

Try:

((β€œaβ€β€¦β€œz”).to_a + (β€œAβ€β€¦β€œZ”).to_a).sort_by { rand }

– Daniel

On Mar 30, 2006, at 4:11 PM, Meino Christian C. 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 W.

a = (β€œAβ€β€¦β€œZ” + β€œaβ€β€¦β€œz”).sort_by { rand }

Tim

Not quite as elegant, but this should work:

((β€˜aβ€™β€¦β€˜z’).to_a + (β€˜Aβ€™β€¦β€˜Z’).to_a).sort_by { rand }

From: Timothy B. [email protected]
Subject: Re:
Date: Fri, 31 Mar 2006 06:22:37 +0900

Hi Tim,

this gives an error with my recent β€œstable-snapshot-ruby”:

a = (β€œAβ€β€¦β€œZ” + β€œaβ€β€¦β€œz”).sort_by { rand }
SyntaxError: compile error
(irb):1: syntax error, unexpected tDOT2
a = (β€œAβ€β€¦β€œZ” + β€œaβ€β€¦β€œz”).sort_by { rand }
^
from (irb):1

Keep hacking!
mcc