Changeset 1022


Ignore:
Timestamp:
Sep 16, 2006, 11:43:36 AM (14 years ago)
Author:
Sam Hocevar
Message:
  • Initialize random seed to getpid()+time(NULL) so that the user does not have to do it.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/cucul/cucul.c

    r1005 r1022  
    2424#   include <stdlib.h>
    2525#   include <string.h>
     26#   include <time.h>
    2627#   if defined(HAVE_ERRNO_H)
    2728#       include <errno.h>
     29#   endif
     30#   include <sys/types.h>
     31#   if defined(HAVE_UNISTD_H)
     32#       include <unistd.h>
    2833#   endif
    2934#endif
     
    273278int cucul_rand(int min, int max)
    274279{
     280    static int need_init = 1;
     281
     282    if(need_init)
     283    {
     284        srand(getpid() + time(NULL));
     285        need_init = 0;
     286    }
     287
    275288    return min + (int)((1.0 * (max - min)) * rand() / (RAND_MAX + 1.0));
    276289}
Note: See TracChangeset for help on using the changeset viewer.