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
SUMMARY

This discussion focuses on generating pseudo-random numbers using the time of day as a seed. Participants highlight that most programming languages, including C++, have built-in functions for this purpose. The Mersenne Twister algorithm is recommended for generating pseudo-random numbers, although it is not suitable for cryptographic applications. A simple method to introduce bias in random number generation is also discussed, involving the modulus operation on the output of the standard random function.

PREREQUISITES
  • Understanding of pseudo-random number generation concepts
  • Familiarity with programming languages like C++ or Octave
  • Knowledge of the Mersenne Twister algorithm
  • Basic mathematical concepts related to modulus operations
NEXT STEPS
  • Research the Mersenne Twister algorithm for pseudo-random number generation
  • Learn how to implement random number generation in C++ using time as a seed
  • Explore the implications of bias in random number generation and how to mitigate it
  • Investigate built-in random number functions in other programming languages
USEFUL FOR

Programmers, game developers, and data scientists who need to generate pseudo-random numbers for simulations or applications without requiring true randomness.

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
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
  • · Replies 13 ·
Replies
13
Views
3K