Hello I just started programming about a month or so ago. I am doing a program that will produce "random" numbers. I am confused on how I need to do this. I have written some code that will follow(some of the variables declared aren't being used I was just experimenting). Any help to guide me in the right direction is appreciated. The problem states: Using the power residue method,
a) Create a function randnum() that accepts a floating point "seed" as a parameter and returns a floating-point random number between 0 and 1.e6.
b) Incorporate the randnum() function created in 7a into a working program that produces 10 random numbers between 0 and 1.e6.
Code:
#include<iostream>
#include<cmath>
#include<ctime>
using namespace std;
float randnumber();
int main()
{
float seed;
char do_again = 'y';
cout<<"This program will produce 10 random numbers given a seed\n"<<endl;
randnumber();
cout<<seed<<endl;
cout<<"Would you like to receive another set of random number? Y or N?\n"<<endl;
cin>>do_again;
while (do_again == 'y')
{
randnumber();
}
system("pause");
return 0;
}
float randnumber()
{
float seed;
float seed1;
char prompt= 'y';
while (prompt == 'y')
{
cout<<"Please enter an odd six-digit integer that is non-divisible by two or five...\n"<<endl;
cin>>seed;
seed = seed * 997;
seed = seed/1000000;
seed1 = seed * 1000000;
seed = seed - seed1;
return seed;
}
}