Home > Back-end >  Each great god, the couple for help about random of random Numbers
Each great god, the couple for help about random of random Numbers

Time:10-04

Why use system time to get a random number is always the same, is turn off after open the number again or so

CodePudding user response:

#include
using namespace std;
#include
#include
The class Q
{
Public:
Int getnumber1 ()
{
Int t;
Int srand ((unsigned int) time (0));
T=rand () 100 + % 1;
return t;
}
Int getnumber2 ()
{
Int t;
Int srand ((unsigned int) time (0));
T=rand () 100 + % 1;
return t;
}
Int getA ()
{
Loop1: int x=getnumber1 ();
Int y=getnumber2 ();
If ((x + y) & lt;=100 & amp; & (x-y) & gt;=0)
Goto loop2;
The else
Goto loop1.
Loop2: double g=getnumber1 () % 2;
If (g==1)
{
Cout<& lt; x<& lt;" + "& lt; & lt; Y<& lt;"="& lt; & lt; endl;
Int m=x + y;
Return m;
}
The else
{
Cout<& lt; x<& lt;" - "& lt; & lt; Y<& lt;"="& lt; & lt; endl;
Int n=x - y;
Return n.
}
}
};
Class A
{
Private:
Q q1;
Static int sum;
Public:
Void all_test ()
{
Int R, S, T;
for(int i=1; i<11. I++)
{

Cout<& lt;" The first "& lt; & lt; i<& lt;" The topic "& lt; & lt; endl;
Int h=q1. GetA ();
Cin> R;
If (R==h)
{
Cout<& lt;" Right!" & lt; & lt; endl;
Sum=sum + 10;
continue;
}
The else
{
Cout<& lt;" Wrong answer, there are two opportunities "& lt; & lt; endl;
Cin> S;
If (S==h)
{
Cout<& lt;" Right "& lt; & lt; endl;
Sum=sum + 7;
continue;
}
The else
{
Cout<& lt;" Wrong answer, as well as an opportunity "& lt; & lt; endl;
Cin> T;
If (T==h)
{
Cout<& lt;" Right "& lt; & lt; endl;
Sum=sum + 5;
continue;
}
The else cout<& lt;" I'm sorry, wrong answer, "& lt; & lt; endl;
Cout<& lt;" The correct answer is "& lt; & lt; H<& lt; endl;
}
}
}
}
Void the print ()
{
Cout<& lt;" Total score for "& lt; & lt; Sum<& lt; endl;
}
Void judge ()
{
If (sum>
=90)Cout<& lt;" SMART "& lt; & lt; endl;
Else if (sum>=80 & amp; & Sum<90)
Cout<& lt;" GOOD "& lt; & lt; endl;
Else if (sum>=70 & amp; & Sum<80)
Cout<& lt;" OK "& lt; & lt; endl;
Else if (sum>=60 & amp; & Sum<70)
Cout<& lt;" PASS "& lt; & lt; endl;
The else cout<& lt;" TRY AGAIN "& lt; & lt; endl;
}

}; Int A: : sum=0;

Int main ()
{
A, a1, a2, a3;
Cout<& lt;" * * * * * * * * * * second grade math test "& lt; & lt; endl;
Cout<& lt;" Below to start "to solve the problem & lt; & lt; endl;
Cout<& lt;" Select a set of test questions, and enter the serial number, "& lt; & lt; endl;
Int p=0;
Cin> p;
The switch (p)
{
Case 1:
{
A1. All_test ();
A1. Print ();
A1. The judge ();
break;
}
Case 2:
{
A2. All_test ();
A2. Print ();
A2. Judge ();
break;
}
Case 3:
{
A3. All_test ();
A3. Print ();
A3. The judge ();
break;
}
}




System (" pause ");
return 0;
}
My idea is to produce different inputs of test questions are different, not 123 the multi-medium, has always been the same problem, jie?

CodePudding user response:

Need to use random seed function: to randomize ();//function, random seeds in the process of a simply call (not repeatable calls, or the sequence of random Numbers generated per second) same

It is important to note that the random seed you just need to call a function, can be placed in the program to start

CodePudding user response:

But I already have a random number and function, is I send the first part of the program are int srand ((unsigned int) time (0));
  • Related