mardi 17 novembre 2015

how can i set frequencies of outcomes of rand() functon in c

i need to write a program to simulate rolling of two dice and store their sum in an array. it is given that frequency of sum=2&12 should be minimum and frequency of sum=7 is maximum. this is the code i've written. i need random numbers between 2 and 12 with said frequencies

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

int main()
{
   int i, n;


   n = 5;
          srand ( time(NULL) );


   for( i = 0 ; i < n ; i++ ) 
   {

      printf("%d\n", rand() % 12);
   }

   return(0);
}




Aucun commentaire:

Enregistrer un commentaire