# More random, please ! :)

**URL:** <https://www.ruby-forum.com/t/more-random-please/57050>\
**Category:** Ruby\
**Created:** [April 6, 2006, 8:29pm UTC](https://www.ruby-forum.com/t/more-random-please/57050 "2006-04-06T20:29:55Z")\
**Posts on this page:** 4\
**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:** [April 6, 2006, 8:29pm UTC](https://www.ruby-forum.com/t/more-random-please/57050/1 "2006-04-06T20:29:55Z")

</div>

Hi,

recently I asked, how one would distribute all letters of  
the alphabet randomly and each statistically equal handled  
(oh…damn…this looks like awful german English…sorry…)

And the solution was too simple, as I would have thought  
of it…hrrmmm…

And now I fear, that the next question will result again in  
such simple kind of answer since we all program ruby here…😉

How can I distribute all 25 letters (I will skip the “J” for this)  
over a 5x5 matrix (two dimensional array) that way, that each letter  
is handled equally from the statistical point of view ?

Thank you very much for your help in advance !  
Ruby!  
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:** [April 6, 2006, 8:42pm UTC](https://www.ruby-forum.com/t/more-random-please/57050/2 "2006-04-06T20:42:11Z")

</div>

Meino Christian C. schrieb:

> How can I distribute all 25 letters (I will skip the “J” for this)  
> over a 5x5 matrix (two dimensional array) that way, that each letter  
> is handled equally from the statistical point of view ?

require “enumerator”

((“A”…“Z”).to\_a-[“J”]).sort\_by{rand}.enum\_slice(5).to\_a

Regards,  
Pit

---

<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:** [April 6, 2006, 8:45pm UTC](https://www.ruby-forum.com/t/more-random-please/57050/3 "2006-04-06T20:45:13Z")

</div>

On Apr 6, 2006, at 2:28 PM, Meino Christian C. wrote:

> such simple kind of answer since we all program ruby here…😉

% irb  
irb(main):001:0\> require ‘enumerator’  
=\> true  
irb(main):002:0\> letters = (“a”…“z”).to\_a  
=\> [“a”, “b”, “c”, “d”, “e”, “f”, “g”, “h”, “i”, “j”, “k”, “l”, “m”,  
“n”, “o”, “p”, “q”, “r”, “s”, “t”, “u”, “v”, “w”, “x”, “y”, “z”]  
irb(main):003:0\> letters.delete(“j”)  
=\> “j”  
irb(main):004:0\> letters2d = letters.sort\_by { rand }.to\_enum  
(:each\_slice, 5).to\_a  
=\> [[“v”, “t”, “p”, “c”, “e”], [“h”, “q”, “z”, “u”, “n”], [“k”, “m”,  
“y”, “g”, “i”], [“x”, “o”, “s”, “w”, “d”], [“a”, “b”, “l”, “r”, “f”]]  
irb(main):005:0\> require ‘pp’  
=\> true  
irb(main):006:0\> pp letters2d  
[[“v”, “t”, “p”, “c”, “e”],  
[“h”, “q”, “z”, “u”, “n”],  
[“k”, “m”, “y”, “g”, “i”],  
[“x”, “o”, “s”, “w”, “d”],  
[“a”, “b”, “l”, “r”, “f”]]  
=\> nil

---

<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:** [April 6, 2006, 9:31pm UTC](https://www.ruby-forum.com/t/more-random-please/57050/4 "2006-04-06T21:31:41Z")

</div>

> […]  
> How can I distribute all 25 letters (I will skip the “J” for this)  
> over a 5x5 matrix (two dimensional array) that way, that each letter  
> is handled equally from the statistical point of view ?

Hi Christian,

you got some answers already, but of course there is always another fun  
way to do stuff with ruby:

letters = [\*(‘A’…‘Z’)] - [‘J’]  
p (0…5).map{(0…5).map{letters.slice!(rand(letters.size))}}

cheers

Simon
