How Can I Generate Psuedo-Random Numbers Using Time of Day as a Seed?

  • Context: High School 
  • Thread starter Thread starter sinners
  • Start date Start date
  • Tags Tags
    Numbers
Click For Summary

Discussion Overview

The discussion revolves around generating pseudo-random numbers using the time of day as a seed. Participants explore various methods and algorithms for achieving this, considering different programming languages and their built-in functions.

Discussion Character

  • Exploratory
  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant seeks help in creating a formula for generating pseudo-random numbers, emphasizing the use of time of day as a seed.
  • Another participant notes that many programming languages have built-in functions for generating pseudo-random numbers using time as a seed, suggesting a Wikipedia article for further reading.
  • A different participant recommends the Mersenne Twister algorithm, mentioning its common use in Octave and cautioning against its use for cryptography.
  • One participant proposes a simple method of generating random numbers by using a regular random number function and applying a modulus operation to introduce bias.
  • Another participant reiterates the use of time as a seed in programming languages like C++, suggesting that it can be fed into a random number function to define bounds.

Areas of Agreement / Disagreement

Participants generally agree on the feasibility of using time as a seed for generating pseudo-random numbers, but there are differing opinions on the best algorithms and methods to use, indicating multiple competing views.

Contextual Notes

Some participants mention specific programming languages and algorithms without resolving the potential biases introduced by certain methods or the implications of using specific algorithms for different applications.

Who May Find This Useful

Readers interested in programming, particularly those looking to implement pseudo-random number generation in their applications, may find this discussion relevant.

sinners
Messages
5
Reaction score
0
Hello, i am writing a program that needs fairly random numbers however not true random numbers. I want to write my own formula however i am no mathematician and i need your help. There will be two variables minimum number and maximum number and i will be using the time of day to help generate more randomization.

thanks sinners
 
Mathematics news on Phys.org
I guess it depends on which programming language you're using, as most programming languages have built in functions which allow you to generate pseudo-random numbers using the time as a seed value. If you're looking for an algorithm in general, check out the wikipedia article and follow the links: http://en.wikipedia.org/wiki/Pseudorandom_number_generator
 
Check out the Mersenne twister algorithm. Octave uses it and keeps telling everyone not to use it for cryptography.

If you want a simpler kind of random number with simple bias, try calling a regular random number, the modding it by a number that does not divide into the size of the placeholder type. i.e. something like

int a=rand();
a=a%6;

This will introduce a slight bias, as a can range from 0-255. Since 256/6 = 42 remainder 4, the numbers 1-4 will get one extra chance to be selected that 5 and 6 do not.
 
If you're using the time of the day, then as said above, you can go ahead and use a function that takes the time for that particular language (you can do this in C++ for example). Use these as your seeds and you can go ahead and define your bounds this way.

Feed this into a random number function if it's built into the language, and you're done.
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 18 ·
Replies
18
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 3 ·
Replies
3
Views
878
Replies
1
Views
1K
  • · Replies 1 ·
Replies
1
Views
1K
Replies
22
Views
5K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K