/*! \file \brief Templates for portable random number generation \date Started 5/17/07 \author George \version\verbatim $Id: gk_mkrandom.h 10711 2011-08-31 22:23:04Z karypis $ \endverbatim */ #ifndef _GK_MKRANDOM_H #define _GK_MKRANDOM_H /*************************************************************************/\ /*! The generator for the rand() related routines. \ \params RNGT the datatype that defines the range of values over which\ random numbers will be generated\ \params VALT the datatype that defines the contents of the array to \ be permuted by randArrayPermute() \ \params FPRFX the function prefix \ */\ /**************************************************************************/\ #define GK_MKRANDOM(FPRFX, RNGT, VALT)\ /*************************************************************************/\ /*! Initializes the generator */ \ /**************************************************************************/\ void FPRFX ## srand(RNGT seed) \ {\ gk_randinit((uint64_t) seed);\ }\ \ \ /*************************************************************************/\ /*! Returns a random number */ \ /**************************************************************************/\ RNGT FPRFX ## rand() \ {\ if (sizeof(RNGT) <= sizeof(int32_t)) \ return (RNGT)gk_randint32(); \ else \ return (RNGT)gk_randint64(); \ }\ \ \ /*************************************************************************/\ /*! Returns a random number between [0, max) */ \ /**************************************************************************/\ RNGT FPRFX ## randInRange(RNGT max) \ {\ return (RNGT)((FPRFX ## rand())%max); \ }\ \ \ /*************************************************************************/\ /*! Randomly permutes the elements of an array p[]. \ flag == 1, p[i] = i prior to permutation, \ flag == 0, p[] is not initialized. */\ /**************************************************************************/\ void FPRFX ## randArrayPermute(RNGT n, VALT *p, RNGT nshuffles, int flag)\ {\ RNGT i, u, v;\ VALT tmp;\ \ if (flag == 1) {\ for (i=0; i