5295: Random number games

description

city ​​like their own games to play, the game requires some random numbers, because the system only comes with the rand to 32768, then Baidu a bit to find it following a function, choose three numbers A, B, C after running K times after generating a random sequence, the random number is then randomly selected city from the end of the sequence numbers, used in the game.

unsigned x = A, y = B, z = C;
unsigned Random() {
  unsigned t;
  x ^= x << 16;
  x ^= x >> 5;
  x ^= x << 1;
  t = x;
  x = y;
  y = z;
  z = t ^ x ^ y;
  return z;
}

After the city to do the game, zzx feel this random sequence is not evenly distributed, so I want to test, but more zzx things, would like you to help this random sequence statistics about the maximum, minimum, average, to help zzx verification.

Entry

Multiple sets of input data, input until the end of file

The first line of three positive integers A, B, C (A, B, C <10000) represents a random seed.
A second line K, represents the generation K (K <10 . 6 ) random numbers.

Export

The first line has two integers, separated by spaces for the minimum and maximum values

The second line has an average of two decimal places are reserved.

 Sample input

1 1 1
10

Sample Output

1 693053781
277275377.80

Code

#include <bits/stdc++.h>
using namespace std;
unsigned x , y , z ;
unsigned Random() {
  unsigned t;
  x ^= x << 16;
  x ^= x >> 5;
  x ^= x << 1;
  t = x;
  x = y;
  y = z;
  z = t ^ x ^ y;
  return z;
}
int main()
{
    unsigned A,B,C;
    while(cin>>A>>B>>C)
    {
      int k;
      cin>>k;
       x = A, y = B, z = C;
        unsigned minn=(1 << 32)-1,maxn=0;
      long long sum=0;
        for(int i=1;i<=k;i++)
        {
            unsigned u=Random();
            minn=min(minn,u);
            maxn=max(maxn,u);
            sum+=u;
        }
        printf("%u %u\n",minn,maxn);
        printf("%.2f\n",sum*1.0/k);
    }
}
View Code

 

Guess you like

Origin www.cnblogs.com/llhsbg/p/11291959.html