/*
 * $Header: /san01/cvs/ashpool/csrc/continuity/mecha/Attic/rnd.c,v 1.8 2004/04/30 13:41:56 aleigh Exp $ 
 */

/*
 * Copyright (c) 1994, 2004 Alex Leigh, All Rights Reserved
 * 
 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ALEX LEIGH The copyright
 * notice above does not evidence any actual or intended publication of such
 * source code.
 * 
 * Disclosure, copying, distribution, or transmission of this code without
 * express permission is prohibited.
 */

/*
 * Generate len random bytes and write them into buf.
 */

#include "mecha.h"

static unsigned int rndGseed;

void rndFinit(void)
{
    rndGseed = utlFtime();

#ifdef HAVE_RAND_R
    srand(rndGseed);
#endif
}

void rndFrandom_bytes(unsigned char *buf, int len)
{
    unsigned char *p = buf;
    int i;

    for (i = 0; i < len; i++) {
#ifdef HAVE_RAND_R
        *p = rand_r(&rndGseed) % 256;
#else

#ifdef WIN32
        *p = rand() % 256;
#else
        *p = random() % 256;
#endif                          /* WIN32 */

#endif                          /* HAVE_RAND_R */
        p++;
    }
}

unsigned int rndFnumber(void)
{
#ifdef HAVE_RAND_R
    unsigned int seed;

    return rand_r(&seed);
#else

#ifdef WIN32
    return rand();
#else
    return random();
#endif                          /* WIN32 */

#endif                          /* HAVE_RAND_R */
}
