Quote:
Originally Posted by xpi0t0s View Post
The way pseudorandom numbers generally work is to modify the seed according to some formula then use the new value as the next seed. So:
initialise seed <- this is the number you enter
random number = f(seed) <- this function returns a random number as a function of seed
random number 2 = f(random number) <- so the result of the previous is fed into the function again.

So you need to keep seed somewhere instead of discarding it, so I would suggest making the "please enter" part a separate part of randnum[ber]() and pass the seed into this function.

A for loop will do the "display 10 random numbers" bit.
Thanks. I have another question. I have to make sure that the number entered "the seed" is not divisible by 2 or 5. I have an error check in my program but it seems even if it is not divisible it still produces the results. I have posted a copy of my updated code.

Code:
#include<iostream>
#include<cmath>
#include<ctime>
using namespace std;
 
double randnum(double);   //function prototype
 
int main()
{
    
    int x;
    double i;
    
    cout<<"This program will produce 10 random numbers given an inital seed\n"<<endl;
 
    cout<<"Please enter the 6 digit seed value non-divisible by 5 or 2\n"<<endl;
    cin>>x;
    
 if (x%5 == 0 || x%2 == 0)
    {
       cout<<"The number entered is not a valid entry"<<endl;
       system("pause");
       return 0;
    }
     
    
else
    {
        cout<<"\nThe random numbers are as follows\n"<<endl;
          
          for(i=1.;i<=10.;i++)           //increments the random numbers
              {
                  x = randnum(x);
                  cout<<x<<endl;
              } 
    
    }
system("pause");
return 0;
}  
 
//The function that will produce the random numbers
double randnum(double x)
{
    double i;
    
       i = int(997.0 * x/ 1000000.);
       x = 997.0 * x - i * 1000000.;
   
    return x;
    
}