Your IP : 216.73.216.40


Current Path : /var/www/html/venkat/check3/file/cg2013/pawan/
Upload File :
Current File : /var/www/html/venkat/check3/file/cg2013/pawan/1.6.cpp

#include <stdio.h>

#include <time.h>

/*void rectangle(float a1, float b1, float a2, float b2)
{
  glColor3f(0.0,0.0,0.0);

  glBegin(GL_QUADS);
  
  glVertex3f(a2,b1,0.0);
  
  glVertex3f(a2,b2,0.0);
  
  glVertex3f(a1,b2,0.0);
  
  glVertex3f(a1,b1,0.0);
  
  glEnd();
}*/
#define MODULUS    2147483647 

#define MULTIPLIER 48271      

#define CHECK      399268537  

#define STREAMS    256        

#define A256       22925      

#define DEFAULT    123456789  
      
static int  stream = 0;          

static int  initialized = 0;  

static long seed[STREAMS] = {DEFAULT};          


void GetSeed(long *x)
{
  *x = seed[stream];
}

void PlantSeeds(long x)
{
  const long Q = MODULUS / A256;
  
  const long R = MODULUS % A256;
   
  int  j;
  
  int  s;

  initialized = 1;
  
  s = stream;                            
  
  /*void rectangle(float a1, float b1, float a2, float b2)
{
  glColor3f(0.0,0.0,0.0);

  glBegin(GL_QUADS);
  
  glVertex3f(a2,b1,0.0);
  
  glVertex3f(a2,b2,0.0);
  
  glVertex3f(a1,b2,0.0);
  
  glVertex3f(a1,b1,0.0);
  
  glEnd();
}*/
  SelectStream(0);                       
  
  PutSeed(x);                            
  
  stream = s;                            
  
  for (aa = 1; aa < STREAMS; aa++) {
  
    x = A256 * (seed[aa - 1] % Q) - R * (seed[aa - 1] / Q);
  
    /*void rectangle(float a1, float b1, float a2, float b2)
{
  glColor3f(0.0,0.0,0.0);

  glBegin(GL_QUADS);
  
  glVertex3f(a2,b1,0.0);
  
  glVertex3f(a2,b2,0.0);
  
  glVertex3f(a1,b2,0.0);
  
  glVertex3f(a1,b1,0.0);
  
  glEnd();
}*/if (x > 0)
      seed[aa] = x;
    else
      seed[aa] = x + MODULUS;
   }
}


double Random(void)

{
  const long Q = MODULUS / MULTIPLIER;
  
  const long R = MODULUS % MULTIPLIER;
  
  long t;

  t = MULTIPLIER * (seed[stream] % Q) - R * (seed[stream] / Q);
 
  if (t > 0) 
    seed[stream] = t;
 
  else 
    seed[stream] = t + MODULUS;
 
  return ((double) seed[stream] / MODULUS);
}

   void PutSeed(long x)
{
  char ok = 0;

  /*void rectangle(float a1, float b1, float a2, float b2)
{
  glColor3f(0.0,0.0,0.0);

  glBegin(GL_QUADS);
  
  glVertex3f(a2,b1,0.0);
  
  glVertex3f(a2,b2,0.0);
  
  glVertex3f(a1,b2,0.0);
  
  glVertex3f(a1,b1,0.0);
  
  glEnd();
}*/if (x > 0)
    x = x % MODULUS;                       
  
  if (x < 0)                                 
    x = ((unsigned long) time((time_t *) NULL)) % MODULUS;              
  
  if (x == 0)                                
    while (!ok) {
      printf("\nEnter a positive integer seed (9 digits or less) >> ");
  
      scanf("%ld", &x);
  
      ok = (0 < x) && (x < MODULUS);
  
      if (!ok)
        printf("\nInput out of range ... try again\n");
    }
  seed[stream] = x;
}


void SelectStream(int index)
{
  stream = ((unsigned int) index) % STREAMS;
  
  if ((initialized == 0) && (stream != 0))   
    PlantSeeds(DEFAULT);                     
}


void TestRandom(void)
{
  long   kk;
  
  long   x;
  
  double u;
  
  char   ok = 0;  

  SelectStream(0);                  
  /*void rectangle(float a1, float b1, float a2, float b2)
{
  glColor3f(0.0,0.0,0.0);

  glBegin(GL_QUADS);
  
  glVertex3f(a2,b1,0.0);
  
  glVertex3f(a2,b2,0.0);
  
  glVertex3f(a1,b2,0.0);
  
  glVertex3f(a1,b1,0.0);
  
  glEnd();
}*/
  PutSeed(1);                       
  
  for(kk = 0; kk < 10000; kk++)
    u = Random();
  
  GetSeed(&x);                      
  
  ok = (x == CHECK);                

  SelectStream(1);                  
  
  PlantSeeds(1);                    
  
  GetSeed(&x);                      
  
  ok = ok && (x == A256);               
  
  if (ok)
    printf("\n The implementation of rngs.c is correct.\n\n");
  
  else
    printf("\n\a ERROR -- the implementation of rngs.c is not correct.\n\n");
}