[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Needing a random number generator for scripting



On Thu, Sep 27, 2001 at 09:20:04AM -0400, dman wrote:
> | /dev/random gives random bits.  I don't know where it is documented.
> | There is a system call random() (see man 3 random).  You could write a
> | wrapper C program to use it in scripts.
> 
> Naw, just use python :-).
> 
> 
> #!/usr/bin/env python
> 
> def my_randint() :

<snip>

> #!/usr/bin/env python
> import random
> print random.random() # this gives a float between 0 and 1
> print random.randint( 0 , 10 ) # this gives an int between 0 and 10
>                                # (the arguments)
> 

Why do you people insist on doing things the hard way?  'echo $RANDOM'
in bash works as well as any of these solutions posted here...  
'echo $(($RANDOM % $randmax))' where randmax is whatever you want the
highest random value to be works, too.

noah

-- 
 _______________________________________________________
| Web: http://web.morgul.net/~frodo/
| PGP Public Key: http://web.morgul.net/~frodo/mail.html 

Attachment: pgpqi6Qi637nz.pgp
Description: PGP signature


Reply to: