gen_homo.c

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



/* taille de la grille 2D représentant l'océan: */
#define OCEAN_SIZE 1000

/* nombre de requins: */
#define SHARK_NB 3000

/* nombre de sardines */
#define SARDINE_NB 15000

/* age maximum des poissons */
#define AGE_MAX 10


int main(int argc, char **argv) {
  char ocean[OCEAN_SIZE*OCEAN_SIZE];
  int i;
  int x,y;
  int age;

  srand(time(NULL));
  memset(ocean, 0, sizeof(char)*OCEAN_SIZE*OCEAN_SIZE);
  fprintf(stdout,"%d\n",OCEAN_SIZE);

  for(i=0; i<SHARK_NB; i++) {
    do {
      x = (int) (((double) OCEAN_SIZE)*rand()/(RAND_MAX+1.0));
      y = (int) (((double) OCEAN_SIZE)*rand()/(RAND_MAX+1.0));
    } while (ocean[(y*OCEAN_SIZE)+x] != 0);
    ocean[(y*OCEAN_SIZE)+x] = 1;
    age = (int) (((double) AGE_MAX)*rand()/(RAND_MAX+1.0));
    fprintf(stdout,"%d %d shark %d\n",x,y,age);
  }

  for(i=0; i<SARDINE_NB; i++) {
    do {
      x = (int) (((double) OCEAN_SIZE)*rand()/(RAND_MAX+1.0));
      y = (int) (((double) OCEAN_SIZE)*rand()/(RAND_MAX+1.0));
    } while (ocean[(y*OCEAN_SIZE)+x] != 0);
    ocean[(y*OCEAN_SIZE)+x] = 1;
    age = (int) (((double) AGE_MAX)*rand()/(RAND_MAX+1.0));
    fprintf(stdout,"%d %d sardine %d\n",x,y,age);
  }


  
  return 0;
}

Generated by GNU enscript 1.6.3.