/****************************************************************/
/* Module : coarse_check.c					*/
/* Section: 13.1 		        			*/
/* Cheney-Kincaid, Numerical Mathematics and Computing, 3rd ed, */
/* Brooks/Cole Publ. Co.                                        */
/* Copyright (c) 2003.  All rights reserved.                    */
/* For educational use with the Cheney-Kincaid textbook.        */
/* Absolutely no warranty implied or expressed.                 */   
/* 								*/
/* Description: Coarse check on the random-number generator     */
/*								*/
/***************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#ifndef RAND_MAX
#define RAND_MAX 2147483648
#endif

void main()
{
  const int n = 10000;
  int i, m = 0;
  float per, *R;

  srand(time(NULL)); /* randomize the seed (optional) */

  R = calloc((n+1), sizeof(float));

  for (i = 0; i <= n; i++)
    R[i] = (float) rand()/ (float) RAND_MAX;

  for (i = 1; i <= n; i++)
  {
    if (R[i] <= 0.5)
      m++;
    if (!(i % 1000))
    {
      per = 100 * (float) m/ (float) i;
      printf(" i = %d, per = %f\n", i, per);
    }
  }

  free(R);
}
