/* rand.c MR 24/07/00 07/06/00 ---------------------------------------------------------------------- Copyright (C) 2000 Menno Rubingh This source code / program is free software; you are allowed to redistribute it and/or to modify it under the terms of the GNU Public Licence (GNU GPL) as published by the Free Software Foundation. See the file 'COPYING' which should have accompanied this source file. This program comes with ABSOLUTELY NO WARRANTY. ---------------------------------------------------------------------- */ #include int n_rand( unsigned int m ) /* Return random integer in [ 0, m ). */ /* Return 0 if m == 0. */ { unsigned int K; if ( m == 0 ) { return 0; } K = ((unsigned int)RAND_MAX + m) / m; return ( rand() / K ); } double f_rand( double max ) //Return a ''double'' random number in interval [ 0.0, max ]. { return ( max * (double)rand() / RAND_MAX ); }