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

Click For Summary

Discussion Overview

The discussion revolves around generating random numbers with a specific focus on achieving a flat (uniform) distribution for applications in colored and white noise. Participants explore different methods and tools for random number generation, including programming languages like Fortran and C++, while addressing the characteristics of uniform versus Gaussian distributions.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant seeks a random number generator that produces a flat distribution, expressing frustration with a Fortran program that yields a Gaussian distribution instead.
  • Another participant suggests using a basic random generator function, such as random(), to achieve a uniform distribution.
  • A different approach is proposed involving the generation of digits of mathematical constants like e or pi, which can be converted into a binary format for use as random numbers.
  • One participant mentions already having a generator for white noise but is looking for a program specifically for colored noise.
  • A C++ code snippet is shared that demonstrates how to generate random numbers within a specified range, with flexibility in defining the minimum and maximum values.
  • There is a clarification that white noise implies a uniform distribution, while colored noise, which has autocorrelation, does not conform to this uniformity.
  • Another participant questions the assertion that colored noise should not be uniform, asking for an explanation and an example related to autocorrelation functions.

Areas of Agreement / Disagreement

Participants express differing views on the nature of colored noise versus white noise, particularly regarding the uniformity of distributions. There is no consensus on the characteristics of colored noise, and the discussion remains unresolved on this point.

Contextual Notes

Some participants may have assumptions about the definitions of colored and white noise that are not fully articulated. The discussion includes various methods for generating random numbers, but the effectiveness and appropriateness of these methods are not agreed upon.

m~ray
Messages
29
Reaction score
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 have 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
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.
 
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.
 
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..
 
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;
 
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 have 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.
 
@ 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.
 
@ kevin : i can produce random numbers by multiple methods. i was talking about a particular type of random numbers.. thanks ne ways.. :)
 

Similar threads

Replies
22
Views
5K
  • · Replies 9 ·
Replies
9
Views
3K
Replies
19
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 6 ·
Replies
6
Views
7K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 11 ·
Replies
11
Views
4K