We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,682 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to make random numbers in python without the random module

I want to be able to generate my own random numbers without using the random module. I want to do this that way I can learn somewhat how to do the big boy code on my own.

3
Contributors
2
Replies
16 Hours
Discussion Span
1 Year Ago
Last Updated
4
Views
Question
Answered
inuasha
Light Poster
26 posts since Dec 2011
Reputation Points: 10
Solved Threads: 3
Skill Endorsements: 0

http://en.wikipedia.org/wiki/Pseudorandom_number_generator

There is even a link to an algorithm with a psuedocode implementation.

Personally, I think you should find something else to work on. I think reimplementing established algorithms will provide little educational value.

lrh9
Posting Whiz in Training
252 posts since Oct 2009
Reputation Points: 122
Solved Threads: 37
Skill Endorsements: 5

Best way to create one is to not to.

Pseudo-random number generators are a very complex subject, so it's better off to use the implementations produced by the people that have a good understanding of the subject.

Python uses the Mersenne twister as the core generator. It produces 53-bit precision floats and has a period of 2**19937-1.
The underlying implementation in C is both fast and threadsafe.

You can of course look at all code for python.
http://svn.python.org/projects/python/trunk/Modules/_randommodule.c
http://svn.python.org/projects/python/trunk/Lib/random.py

Pitfalls in Random Number Generation

def get_random_number():
    '''Chosen bye a fair dice roll,guaranteed to be random'''
    return 4
snippsat
Posting Shark
954 posts since Aug 2008
Reputation Points: 482
Solved Threads: 343
Skill Endorsements: 8
Question Answered as of 1 Year Ago by snippsat and lrh9

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0602 seconds using 2.67MB