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
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
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
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 +0900Hi,
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β¦) thata=(β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.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs