# (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.

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!

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 ?

Keep hacking!
mcc

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.