| | |
random number
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2007
Posts: 6
Reputation:
Solved Threads: 0
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 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.
•
•
•
•
hi,this sandy patel
. 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?.
Last edited by Aia; Apr 11th, 2007 at 9:01 pm.
•
•
Join Date: Apr 2007
Posts: 6
Reputation:
Solved Threads: 0
•
•
•
•
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?.
my effort is as under
:
c Syntax (Toggle Plain Text)
#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,
C++ Syntax (Toggle Plain Text)
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.
Last edited by WaltP; Apr 14th, 2007 at 12:14 am. Reason: Added CODE tags -- you actually typed right over how you use them when you entered this post...
With the fuction rand() your computer will try to produce a ramdom number.
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:
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
C++ Syntax (Toggle Plain Text)
random = rand() % 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:
C++ Syntax (Toggle Plain Text)
srand(seed);
pseudo-random number.
Here's a link for example.
http://www.dreamincode.net/forums/showtopic14057.htm
•
•
Join Date: Apr 2007
Posts: 6
Reputation:
Solved Threads: 0
•
•
•
•
With the fuction rand() your computer will try to produce a ramdom number.
will assign to variable random the result of the evaluation of the function rand() in the range between 0 and 9.C++ Syntax (Toggle Plain Text)
random = rand() % 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:
where seed is the number inputed from user or system to use as a base for that chaos needed to originate aC++ Syntax (Toggle Plain Text)
srand(seed);
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;
![]() |
Similar Threads
- Random number generator's (C++)
- Need to know how to create a database that will generate a random number (Database Design)
- Random number generation (C)
- Help with random number gen (C++)
Other Threads in the C++ Forum
- Previous Thread: Help with priority queues
- Next Thread: Dev-c++
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






