[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Smoking hash-ish: Letter mapping...

Meino Christian Cramer

8/5/2006 6:48:00 PM

3 Answers

Meino Christian Cramer

8/5/2006 7:04:00 PM

0

Meino Christian Cramer

8/5/2006 7:07:00 PM

0

Logan Capaldo

8/5/2006 7:21:00 PM

0


On Aug 5, 2006, at 3:07 PM, Meino Christian Cramer wrote:

> Oh...there is another issue:
>
> With encmap=Hash[*('A'..'Z').to_a.sort{rand(2)}] I only will get 13
> instead of 26 mappings! How can I fix /that/ ?
>
> Keep encoding! :)
> mcc
>

Actually its generally considered better to do sort_by{rand} that sort
{rand(2)}

If you only want to randomize key or value you can do

first = ("A".."Z").to_a
second = ("A".."Z").sort_by{rand}

encmap = Hash[ *first.zip(second).flatten ]