Random...

Lemniscate d_blade8 at hotmail.com
Mon Mar 25 18:50:12 EST 2002


I would tend to agree with this approach, for simplicity.  One could
take it to an extreme and have a program that creates a file and
writes large random numbers to the file until the file is nothing but
a huge (HUGE) string of numbers (with a file size in the MBs).  What
you may end up with a number that is a couple of million digits long. 
Then, you write a module to access it.  The module will ask the user
how many digits they desire in their random number, the module will
start off at a arbitrary point in the file and read that many digits. 
The module will convert the string of numbers into a L and return it.
Alternatively, write a program that will seed a random number [0-9]
and add it to a string 'x' times where x is the number of digits
desired.  Something like:

def CustomRandom(NumberOfDigits = 95):
myDigits = NumberOfDigits   #if you want some sort of default use this
line, not the next
myDigits = raw_input("How many digits?\n>>> ")
myString = ""
for x in range(myDigits):
    random_num = <Create a random number by some method here>
    myString += random_num
<Cast myString into an L/int, maybe do some testing (maybe you want an
odd number or something, and return it>

You just have to make sure you use a good method to generate your
random digits.  I used something like this once to test some software
for stuff like buffer overflow problems.  It was relatively easy once
I got started.  Later.





Uwe Schmitt <uwe at rocksport.de> wrote in message news:<a7nrvd$7sbdt$2 at hades.rz.uni-sb.de>...
> FREDRIK HULDTGREN <tdi01fhu at syd.kth.se> wrote:
> | I want to generate random numbers, very large random numbers. If I use
> | randrange() I get an out of bounds error since it only supports numbers
> | up to (2**31)-1. However, I can use uniform(), but then I get the number
> | returned in 7.9655120654553743e+018 or something simaler, and I would
> | rather have it in a "L" format(796551206545537430183218312890381031L).
> | How do I do this?
>  
> | thanx
> | /Fredrik
> 
> You could generate two random numbers and clue them together to
> a longer number.
> 
> there is a mp (multip precision) library at http://gmpy.sourceforge.net
> 
> Greetings, Uwe



More information about the Python-list mailing list