# (no subject)

**URL:** <https://www.ruby-forum.com/t/no-subject/93329>\
**Category:** Ruby\
**Created:** [March 30, 2006, 10:36pm UTC](https://www.ruby-forum.com/t/no-subject/93329 "2006-03-30T22:36:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Meino\_Christian\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Meino\_Christian\_C](https://www.ruby-forum.com/u/Meino_Christian_C)\
**Post date:** [March 30, 2006, 10:36pm UTC](https://www.ruby-forum.com/t/no-subject/93329/1 "2006-03-30T22:36:30Z")

</div>

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 ! 🙂

Keep hacking!  
mcc

---

<div class="post-metadata">

**Author:** ![Meino\_Christian\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Meino\_Christian\_C](https://www.ruby-forum.com/u/Meino_Christian_C)\
**Post date:** [March 30, 2006, 10:39pm UTC](https://www.ruby-forum.com/t/no-subject/93329/2 "2006-03-30T22:39:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Meino\_Christian\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Meino\_Christian\_C](https://www.ruby-forum.com/u/Meino_Christian_C)\
**Post date:** [March 30, 2006, 10:57pm UTC](https://www.ruby-forum.com/t/no-subject/93329/3 "2006-03-30T22:57:47Z")

</div>

From: James Edward G. II [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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! 🙂

Have a nice time!  
mcc

---

<div class="post-metadata">

**Author:** ![Meino\_Christian\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Meino\_Christian\_C](https://www.ruby-forum.com/u/Meino_Christian_C)\
**Post date:** [March 30, 2006, 11:13pm UTC](https://www.ruby-forum.com/t/no-subject/93329/4 "2006-03-30T23:13:10Z")

</div>

From: James Edward G. II [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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

---

<div class="post-metadata">

**Author:** ![Meino\_Christian\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Meino\_Christian\_C](https://www.ruby-forum.com/u/Meino_Christian_C)\
**Post date:** [March 30, 2006, 11:22pm UTC](https://www.ruby-forum.com/t/no-subject/93329/5 "2006-03-30T23:22:20Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> 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

---

<div class="post-metadata">

**Author:** ![Meino\_Christian\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Meino\_Christian\_C](https://www.ruby-forum.com/u/Meino_Christian_C)\
**Post date:** [March 30, 2006, 11:22pm UTC](https://www.ruby-forum.com/t/no-subject/93329/6 "2006-03-30T23:22:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Meino\_Christian\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Meino\_Christian\_C](https://www.ruby-forum.com/u/Meino_Christian_C)\
**Post date:** [March 30, 2006, 11:25pm UTC](https://www.ruby-forum.com/t/no-subject/93329/7 "2006-03-30T23:25:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Meino\_Christian\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Meino\_Christian\_C](https://www.ruby-forum.com/u/Meino_Christian_C)\
**Post date:** [March 30, 2006, 11:25pm UTC](https://www.ruby-forum.com/t/no-subject/93329/8 "2006-03-30T23:25:31Z")

</div>

a = (“A”…“Z” + “a”…“z”).sort\_by { rand }

Tim

---

<div class="post-metadata">

**Author:** ![Meino\_Christian\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Meino\_Christian\_C](https://www.ruby-forum.com/u/Meino_Christian_C)\
**Post date:** [March 30, 2006, 11:25pm UTC](https://www.ruby-forum.com/t/no-subject/93329/9 "2006-03-30T23:25:32Z")

</div>

Not quite as elegant, but this should work:

((‘a’…‘z’).to\_a + (‘A’…‘Z’).to\_a).sort\_by { rand }

---

<div class="post-metadata">

**Author:** ![Meino\_Christian\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Meino\_Christian\_C](https://www.ruby-forum.com/u/Meino_Christian_C)\
**Post date:** [March 31, 2006, 6:18am UTC](https://www.ruby-forum.com/t/no-subject/93329/10 "2006-03-31T06:18:44Z")

</div>

From: Timothy B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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
