I'm looking for an example about constructing data to be random (I know about the rand() function) but the data should be distributed in different ways (evenly, accelerating)- thanks for helping...and excuse my english
This is a discussion on mathematical random distribution within the C++ Programming forums, part of the General Programming Boards category; I'm looking for an example about constructing data to be random (I know about the rand() function) but the data ...
I'm looking for an example about constructing data to be random (I know about the rand() function) but the data should be distributed in different ways (evenly, accelerating)- thanks for helping...and excuse my english
your english is fine : )
Hope this helps, i rlly don't kno much bout randomness:
Code:/* // Name: Code Example - generating random numbers // Description:Today in class we went over a few different concepts. I wrote my own examples of these C++ concepts. // By: Jared Bruni // // // Inputs:None // // Returns:None // //Assumes:None // //Side Effects:None //This code is copyrighted and has limited warranties. */ /* random number example written by Jared Bruni www.LostSideDead.com */ #include<iostream> #include<time.h> using namespace std; int main() { srand(time(NULL)); // seed randomization // now generate and display 10 random numbers 0-10 for(int i = 0; i < 500; i++) { cout << "random number: " << rand()%10 << endl; } return system("pause"); }
This is a simple function that gives good distribution:
-PreludeCode:int nrand ( int n ) { if ( n <= 0 || n > RAND_MAX ) throw domain_error ( "Argument to nrand is out of range" ); const int bucket_size = RAND_MAX / n; int r; do { r = rand() / bucket_size; } while ( r >= n ); return r; }
My best code is written with the delete key.