tags:

views:

117

answers:

4
 I have tried to write a random number generators 

int generate_random_number(int min , int max )/*min and max describe the range*/
{
    /* assume range is 1-4 min=1 max=4*/
     create an array b[max] and fill with 1,2,3,4;
      shuffle the array b    /*shuffle is an another function*/
   /* shuffle uses Fısher and yates' modern method*/
     copy b to array a /*for min from 1 to min-1 a[min]=b[min;]*/
    c=a[0];  
    erase a[0];
    update array a;
   return c;
}

Is it is a good way to get a random number from function ,
or are there any other efficient  algorithm ?
+2  A: 

There are many questions like this here in SO. Try to first look them before re-asking stuff like that again. :)

For example: Create random numbers

InsertNickHere
+3  A: 

This is not a good way to generate random numbers, because it requires shuffling array. Shuffling array, in turn, requires random number generation, so you get chicken-and-egg problem.

el.pescado
+2  A: 

Your shuffle already uses a random number generator and a range calculation. Why not use this in the first place?

Secure
A: 

See http://ccan.ozlabs.org/browse/ccan/isaac

you probably want isaac.c and isaac.h

Spudd86