hi,this sandy patel
i have problem related to random number genre.
ter .
i don't understand from which is number from i have to start my program?
and,upto witch number i have to go?
The following steps describe the algorithm.
Step 1: Enter an odd 4-digit integer seed number that is not divisible by 2 or 5.
Step 2: Multiply the seed number by 97.
Step 3: Extract the lower 4 digits of the result produced by step 2.
This is the procedure for Step 3.
3a: Divide the number by 104
3b: Keep the integer part of the result of step 3a.
3c: Multiply the result, in 3b, by 104.
3d: Subtract this result from the number produced by step 2.
Use this random number as the new seed.
Step 4: Repeat Steps 2 and 3 to generate as many random numbers as required.
Write a program that tests the effectiveness of this algorithm.
To do this we will generate a large number of pseudorandom integers, record them and
investigate the randomness of the numbers produced.
However, the algorithm above will produce numbers up to 9999. To check the randomness of
the output we would like to record the number of times each integer was generated but with
10000 numbers this would be a tedious process. Our task is to make a quick check possible
within the limits of our resources. The quickest way to present the results is on the screen but
it would be impractical to present all 10000 integers. To overcome this we will limit the test
to random numbers between 0 and 9. These can then be easily tabulated on the screen.
Your task then is to generate a large number (maximum 1000) of pseudorandom integers
between 0 and 9. You will use the algorithm above to generate the 4 digit pseudorandom
numbers and from each extract one of the 4 digits to produce a random number of 0-9.
Start by initialising 10 variables, used as counters, to zero. The counters will keep a sum of
the occurrence of each random digit generated. Print out the number of 0s, 1s, 2s etc. that
occurred and the percentage of time they occurred.
A sample output is shown below.

i was gonna bump it but heres some advice.

in most real systems the initial seed is the time

in your case you start by entering an odd 4-digit integer seed number that is not divisible by 2 or 5.

hi,this sandy patel

Hello :). Welcome to the forum.

Let's start from the beginning.
I hope you are not expecting people to do your home work.
In fact, is opposite to the philosophy of this forum to do that. Read about it, here.

Now that you know that. Let's not get overwhelmed by your assignment.
What exactly do you want to learn first?. What do you not understand at all?.

Hello :). Welcome to the forum.

Let's start from the beginning.
I hope you are not expecting people to do your home work.
In fact, is opposite to the philosophy of this forum to do that. Read about it, here.

Now that you know that. Let's not get overwhelmed by your assignment.
What exactly do you want to learn first?. What do you not understand at all?.

hi,thanks for reply;
my effort is as under


:

#include<iostream.h>
#include<cmath>
#include<iomanip.h>

int main()
{
  //declare and initialize objects.
 int step_a;
 int step_b;
 int step_c;
 int step_d;
 int amount;
 int seed;
 int amount1;
    int store;
 int counter;
 counter=0;
 int a;
 a=0;
 int randomnumber;
 int count=0;
 int variable1=0;
 //give a heading to program
 cout<<"A program to test an algorithm that produces a list of pseudo-random numbers of magnitude between 0 and 9:\n\n\n";
    // promat user to enter a seed value
 cout<<"Enter a  four digit positive number,-not divisible by 2 or 5:";
 cin>>seed;
    
 { 

  
         if((seed>=1000&&seed<9999)&&(seed%2||seed%5))
    
 do
   {
        step_a=seed*97;
  step_b=step_a/pow(10,4); 
  step_c=step_b*pow(10,4);
  step_d=step_a-step_c;
        amount=step_d;
  seed=amount;
  cout<<"Enter a  four digit positive number,- not divisible by 2 or 5:"<<amount<<endl;
  counter=counter+1;
   } while((seed>=1000&&seed<9999)&&(seed%2||seed%5));
   
cout<<"\n"<<"\n"<<"how many random number will the program generat:"<< counter<<endl;
cout<<"\n"<<"\n"<<    setw(4)    <<"random number    "<<     setw(4)   <<      "count"<<endl;
while((a<10))
{
randomnumber=a;
cout<<setw(6)  <<  randomnumber   <<   setw(6)    <<             count    <<  endl;
a+=1;
cout<<variable1<<counter<<endl;
}
 return 0; 
 
}
}

now,i just wants to know that,how to count every integer in each random line?
means,

randomnumber   count   percent
 0                        12        8
 1                        23        4
 2                        14        5
 3                        11        9

i have to create this type of table,
thanks in advance for your help.
bye.

With the fuction rand() your computer will try to produce a ramdom number.

random = rand() % 9;

will assign to variable random the result of the evaluation of the function rand() in the range between 0 and 9.
The problem is that it will produce always the same number, not matter how many times you use it.

To imitate the chaos needed for a random number you need to use the function srand() before using rand().
This is done by declaring once something like this:

srand(seed);

where seed is the number inputed from user or system to use as a base for that chaos needed to originate a
pseudo-random number.

Here's a link for example.

http://www.dreamincode.net/forums/showtopic14057.htm

With the fuction rand() your computer will try to produce a ramdom number.

random = rand() % 9;

will assign to variable random the result of the evaluation of the function rand() in the range between 0 and 9.
The problem is that it will produce always the same number, not matter how many times you use it.

To imitate the chaos needed for a random number you need to use the function srand() before using rand().
This is done by declaring once something like this:

srand(seed);

where seed is the number inputed from user or system to use as a base for that chaos needed to originate a
pseudo-random number.

Here's a link for example.

http://www.dreamincode.net/forums/showtopic14057.htm

Thank u very much for your reply.
but,
ASper our assigenment condition i can't use rand() or srand(seed);
please help me out;
loking for your reply;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.