Can I Get a Flat Distribution with a Random Number Generator?

In summary, according to the conversation, you can produce a variety of random numbers with a variety of distributions by manipulating the range and min number.
  • #1
m~ray
31
0
hello , i wanted to get a random number generator for colored as well as white noise. all numbers in the range should be equally likely to be produced.. ie, say within 1-100, 50 shouldn't hav an extra high probability. on the net i found this fortran program.
http://fortran.com/gauss_random

when i run it and plot the random numbers , i see that more numbers are clustered at the mean. gaussian sort of distribution.

can i get some where or some how a flat distribution ??
 
Technology news on Phys.org
  • #2
You want the good old regular random generator that produces a flat distribution. I don't know what it's called in fortran, but random() is a good bet. As you've noticed, the one you picked makes a "normal" or gaussian distribution which is useful for simulating test scores and stuff like that.
 
  • #3
If you don't need a huge number of random numbers, you can download one of those programs that quicky generates e or pi to millions of digits with an optional binary output, then use that binary file as large array of random numbers. I used apfloat's (do a web search) aptest program to generate pi in hex, then converted that to binary with my own program.

On a side note, if you wnat a Gausian (normal) distribution, based on evenly distributed random numbers, you can sum them up in groups of 8 to get a good approximate bell curve. Summing 2 two at a time will produce a triangle shape curve with a peak in the middle. Summing 3 or more will start to produce a bell like curve, and with 8 at a time or more, it starts to get pretty close.
 
  • #4
thanks.. but i already have random number generator for 'white noise'.. if anyone has used 'colored noise' random number generator in his/her project or work, then please let me know where i can find that program. thanks..
 
  • #5
in c++

Code:
#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;

int main() {
	int x;
	srand((unsigned) time(NULL));
	x = (rand() %100) + 1;
	cout << x << endl;
}

x = (rand() %100) + 1 => you can change the "100" into any number you want to be the highest possible number to generate - min number. You also can manipulate the min num by change the "1" , into the min number + 1 , ex : if the range that you want is 53 until 100 => x = (rand() %47) +54;
 
  • #6
m~ray said:
hello , i wanted to get a random number generator for colored as well as white noise. all numbers in the range should be equally likely to be produced.. ie, say within 1-100, 50 shouldn't hav an extra high probability.
I don't understand what you are asking for. If you want "all numbers in the range should be equally likely to be produced", that is white noise. If you want "coloured noise", then you don't want a uniform distribution.
 
  • #7
@ Dr. greg, u mean colored noise ( having auto-correlation ) is not uniform ? can u please explain me y it shouldn't be uniform ? may b u can take the example of producing say 10 random numbers between 1-100, which are related according to some auto correlation function. thank you. i am having problem in visualizing this colored noise. please help.
 
  • #8
@ kevin : i can produce random numbers by multiple methods. i was talking about a particular type of random numbers.. thanks ne ways.. :)
 

FAQ: Can I Get a Flat Distribution with a Random Number Generator?

What is a random number generator?

A random number generator is a computational tool that produces a sequence of numbers that appear to be random. These numbers are generated through a mathematical algorithm and can be used for a variety of purposes.

Why is a random number generator important in scientific research?

A random number generator is important in scientific research because it allows researchers to generate unbiased and unpredictable data for their experiments. This helps to reduce the potential for bias and ensures the validity of the results.

What are the different types of random number generators?

There are two main types of random number generators: pseudo-random number generators (PRNGs) and true random number generators (TRNGs). PRNGs use an algorithm to generate numbers that appear random, while TRNGs use physical phenomena, such as atmospheric noise, to generate truly random numbers.

How do scientists test the randomness of a random number generator?

Scientists use statistical tests, such as the chi-square test and the Kolmogorov-Smirnov test, to evaluate the randomness of a random number generator. These tests analyze the distribution of the generated numbers and determine if they deviate significantly from a truly random distribution.

Are there any limitations to using a random number generator in scientific research?

Yes, there are limitations to using a random number generator in scientific research. PRNGs can potentially produce patterns or correlations in the generated numbers, which can affect the validity of the results. TRNGs, on the other hand, can be affected by external factors, such as electromagnetic interference, which can compromise the randomness of the generated numbers.

Back
Top