On 29.06.2009 17:18, Lloyd Linklater wrote:
> I have been trying to generate a random string.  One approach in, say,
> pascal would be something like this:
> 
> function GetRandomChar: char;
> var
>   r: integer;
> begin
>   r := random(36);
>   case r of
>     0..25: result := chr(ord('a') + r);
>     else : result := chr(ord('0') + r);
>   end;
> end;
> 
> I know that there is something like "a".next but I need something more
> like "a" + some_random_value.  Even though it is more terse than the
> Pascal, I am trying to avoid something time consuming and inelegant like
> 
> s = "a"
> rand(26).times do {s.next!}
> 
> Any suggestions?

Stealing generate_id from my git repo:

http://github.com/rklemme/muppet-laboratories/blob/16dc8851554bf29cee37a0dd75a7869c99b10c7d/bin/test-gen.rb

Kind regards

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/