| | |
Generating random nos without using random module
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
0
#12 29 Days Ago
There are of course others out there. But this one is the simplest and produce decent set. You can search for pseudorandom number generator algos.
http://en.wikipedia.org/wiki/List_of_algorithms
>> Probably the best inputs is date/time, used memory, random user input, and my favorite mouse movement(truecrypt uses this).
These all will help you to seed......but to generate sets you need some method!
http://en.wikipedia.org/wiki/List_of_algorithms
>> Probably the best inputs is date/time, used memory, random user input, and my favorite mouse movement(truecrypt uses this).
These all will help you to seed......but to generate sets you need some method!
•
•
Join Date: Oct 2009
Posts: 14
Reputation:
Solved Threads: 0
0
#13 28 Days Ago
•
•
•
•
There are of course others out there. But this one is the simplest and produce decent set. You can search for pseudorandom number generator algos.
http://en.wikipedia.org/wiki/List_of_algorithms
>> Probably the best inputs is date/time, used memory, random user input, and my favorite mouse movement(truecrypt uses this).
These all will help you to seed......but to generate sets you need some method!
Wats the meaning of seed?
n sets refers to the list of random nos?
0
#14 28 Days Ago
This Python code shows you how to pick a random number from a list ...
The list is generated this way ...
I made the rand_list relatively short for this example, normally you may want to go for a length of >1000.
python Syntax (Toggle Plain Text)
# picking random numbers from a list # Python2 syntax def pick_rand(rand_list, start=-1, incr=1): """ closure based function that cycles through rand_list one index at a time for each call, index resets to zero at end of list """ def inner(): inner.index += incr if inner.index >= len(rand_list): inner.index = 0 return rand_list[inner.index] inner.index = start return inner # random number list of 100 numbers from 0 to 99 # created by timing user input events rand_list = [ 6, 40, 3, 6, 93, 81, 84, 56, 43, 31, 34, 21, 9, 96, 84, 87, 6, 9, 12, 0, 87, 59, 31, 18, 6, 9, 96, 68, 56, 59, 31, 3, 75, 62, 34, 21, 9, 96, 68, 56, 43, 0, 71, 59, 31, 34, 6, 78, 65, 37, 25, 96, 84, 71, 59, 46, 34, 6, 9, 81, 53, 40, 28, 84, 56, 43, 65, 84, 87, 59, 62, 50, 21, 9, 96, 84, 71, 59, 46, 18, 90, 93, 81, 84, 71, 59, 31, 34, 53, 40, 46, 3, 75, 75, 50, 6, 65, 21, 87, 15 ] # testing only ... print len(rand_list) # 100 print "average = %d" % (sum(rand_list)//len(rand_list)) # 48 # needed! rand = pick_rand(rand_list) # show 10 random numbers for k in range(10): print rand(), # show another 10 random numbers for k in range(10): print rand(),
python Syntax (Toggle Plain Text)
# a time based random number generator # that uses the random time between a user's input events # to create a list of random numbers # Python2 syntax import time def random_number(low, high): """ a time based random number generator uses the random time between a user's input events returns an integer between low and high-1 """ return int(low + int(time.time()*1000) % (high - low)) low = 0 high = 100 count = 0 rand_list = [] print "Press enter for a random number (q to quit):" while True: sel = raw_input() if sel == 'q': break rand = random_number(low, high) rand_list.append(rand) # give user feedback print "%d --> %d" % (count, rand) count += 1 print rand_list """my rand_list 0f 100 random numbers between 0 and 99 --> [6, 40, 3, 6, 93, 81, 84, 56, 43, 31, 34, 21, 9, 96, 84, 87, 6, 9, 12, 0, 87, 59, 31, 18, 6, 9, 96, 68, 56, 59, 31, 3, 75, 62, 34, 21, 9, 96, 68, 56, 43, 0, 71, 59, 31, 34, 6, 78, 65, 37, 25, 96, 84, 71, 59, 46, 34, 6, 9, 81, 53, 40, 28, 84, 56, 43, 65, 84, 87, 59, 62, 50, 21, 9, 96, 84, 71, 59, 46, 18, 90, 93, 81, 84, 71, 59, 31, 34, 53, 40, 46, 3, 75, 75, 50, 6, 65, 21, 87, 15] """
Last edited by vegaseat; 28 Days Ago at 1:36 pm.
May 'the Google' be with you!
•
•
Join Date: Sep 2009
Posts: 108
Reputation:
Solved Threads: 12
0
#15 25 Days Ago
•
•
•
•
Right now i have used time for my input. Could you please give a bit more info on used memory and mouse movement?
If you need me to I can post some examples of pyHook, xlib, and memory fetching.
NOTE: sudo doesn't apply to real life situations.
![]() |
Similar Threads
- display random images from folder (PHP)
- Generating a random card from a deck with python. (Python)
- Random rotation of a random vector (C++)
- Pascal random numbers are not random (Pascal and Delphi)
- Compile time errors in C++ while generating random numbers (C++)
- Logic behind generating random number (C)
- problem in generating non repeated random numbers (C)
- Random numbers...really random?? (Java)
Other Threads in the Python Forum
- Previous Thread: How to use MD5 in Python?
- Next Thread: how to use getpass in python
| Thread Tools | Search this Thread |
advanced aliased bash beginner bits calling casino changecolor class clear command convert corners count csv cturtle cursor def definedlines dictionary digital dynamic dynamically events examples external file float format frange function google gui hints homework i/o iframe import info input java line linux list lists loop matching mouse multiple number numbers obexftp output parsing path port prime programming projects py py2exe pygame pygtk python random rational raw_input recursion return scrolledtext signal singleton skinning stderr string strings subprocess table tails terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode urllib urllib2 valueerror variable voip web-scrape whileloop windows word wxpython






