//RandomNumber.h
#ifndef RANDOM_NUMBER_
#define RANDOM_NUMBER_
#include <time.h>
const unsigned long maxshort = 65536L;
const unsigned long multiplier = 1194211693L;
const unsigned long adder = 12345L;
class RandomNumber
{
private:
 unsigned long randSeed;
public:
 RandomNumber(unsigned long s = 0);
 unsigned short Random(unsigned long n);
 double fRandom(void);
};
RandomNumber::RandomNumber(unsigned long s)
{
 if(s == 0)
 {
  randSeed = time(0);
 }
 else
 {
  randSeed = s;
 }
}
//return random interger 0 <= value <= n-1 < 65536
unsigned short RandomNumber::Random(unsigned long n)
{
 randSeed = multiplier * randSeed + adder;
 return (unsigned short)((randSeed >> 16) % n);
}
//return (value in rang 0 ~ 65535) / 65535
double RandomNumber::fRandom(void)
{
 return Random(maxshort)/double(maxshort);
}
#endif
 
 
//main.cpp
#include <iostream.h>
#include "RandomNumber.h"
void main()
{
 RandomNumber rnd;
 //generate 20 numbers range from 1 to 10;
 for(int i=0; i<20; i++)
 {
  cout<<1+rnd.Random(10)<<" ";
 }
 cout<<endl;
}