mardi 16 octobre 2018

Make Random Numbers Generator with average value

I need to make random numbers generator without built-in function and with an average value of not more than 0.5. It must generate 10000 numbers and preferably they should not be repeated. For example code of PRNG below:

#include <iostream>
using namespace std;

unsigned int Rand()
{
    static unsigned int seed = 5323;
    seed = 8253729 * seed + 2396403;
    return seed  % 32768;
}

int main()
{
    for (int count=1; count <= 10000; ++count)
{
        cout << Rand() << "\t";
        if (count % 10 == 0)
        cout << "\n";
}

    return 0;
}

As a result I have 10000 numbers, and if I try to calculate average value of 10 numbers from the first line I won't receive 0.5. For example in first line we receive:

31222,24489,32444,25391,6402,11317,10440,6843,3598,3777

The average value is: 15592.3. What can I do with it to decrease this value?




Aucun commentaire:

Enregistrer un commentaire