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

  • Thread starter sinners
  • Start date
  • Tags
    Numbers
In summary, the conversation discusses the need for generating fairly random numbers using a formula, with the use of two variables and the time of day. Suggestions are given for using built-in functions or algorithms, such as the Mersenne twister, or creating a simpler random number by modding a regular random number. It is also mentioned that the time of day can be used as a seed value for generating random numbers.
  • #1
sinners
5
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
  • #2
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
 
  • #3
Check out the Mersenne twister algorithim. 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.
 
  • #4
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.
 

What are pseudo-random numbers?

Pseudo-random numbers are a sequence of numbers that appear to be random but are actually generated by an algorithm. They are used in computer programs to simulate randomness and are not truly random.

Why are pseudo-random numbers used?

Pseudo-random numbers are used in situations where true randomness is not necessary, such as in simulations, games, and statistical analysis. They are also used in cryptography to generate secure keys and in scientific experiments to control variables.

How are pseudo-random numbers generated?

Pseudo-random numbers are generated by using mathematical algorithms that produce a sequence of numbers based on a starting value known as a seed. These algorithms use complex calculations to create a sequence of numbers that appear random but can be reproduced if the seed is known.

What is the difference between pseudo-random numbers and true random numbers?

The main difference between pseudo-random numbers and true random numbers is that true random numbers are generated by physical processes that are unpredictable, such as atmospheric noise or radioactive decay. Pseudo-random numbers, on the other hand, are generated by algorithms and are not truly random.

Are pseudo-random numbers truly random?

No, pseudo-random numbers are not truly random. They are generated by algorithms and can be reproduced if the seed is known. However, they can appear to be random and are useful in many applications where true randomness is not necessary.

Similar threads

Replies
1
Views
727
  • Programming and Computer Science
Replies
1
Views
579
Replies
4
Views
253
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Programming and Computer Science
Replies
22
Views
3K
Replies
1
Views
927
Replies
6
Views
2K
  • Programming and Computer Science
Replies
10
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
10
Views
1K
  • Programming and Computer Science
Replies
12
Views
2K
Back
Top