1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/eh/random_number.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,39 @@
1.4 +/***********************************************************************************
1.5 + random_number.cpp
1.6 +
1.7 + * Copyright (c) 1997
1.8 + * Mark of the Unicorn, Inc.
1.9 + *
1.10 + * Permission to use, copy, modify, distribute and sell this software
1.11 + * and its documentation for any purpose is hereby granted without fee,
1.12 + * provided that the above copyright notice appear in all copies and
1.13 + * that both that copyright notice and this permission notice appear
1.14 + * in supporting documentation. Mark of the Unicorn makes no
1.15 + * representations about the suitability of this software for any
1.16 + * purpose. It is provided "as is" without express or implied warranty.
1.17 +
1.18 +***********************************************************************************/
1.19 +#include "random_number.h"
1.20 +#include "Prefix.h"
1.21 +#if defined (EH_NEW_HEADERS)
1.22 +# include <functional>
1.23 +# include <cstdlib>
1.24 +#else
1.25 +# include <function.h>
1.26 +# include <stdlib.h>
1.27 +#endif
1.28 +
1.29 +unsigned random_number( size_t range )
1.30 +{
1.31 +#if !defined( __SGI_STL )
1.32 + if (range == 0) return 0;
1.33 + return (unsigned)(EH_STD::rand() + EH_STD::rand()) % range;
1.34 +#else
1.35 + static EH_STD::subtractive_rng rnd;
1.36 + if (range==0) return 0;
1.37 + return rnd(range);
1.38 +#endif
1.39 +}
1.40 +
1.41 +// default base for random container sizes
1.42 +unsigned random_base = 1000;