sl@0
|
1 |
/***********************************************************************************
|
sl@0
|
2 |
random_number.cpp
|
sl@0
|
3 |
|
sl@0
|
4 |
* Copyright (c) 1997
|
sl@0
|
5 |
* Mark of the Unicorn, Inc.
|
sl@0
|
6 |
*
|
sl@0
|
7 |
* Permission to use, copy, modify, distribute and sell this software
|
sl@0
|
8 |
* and its documentation for any purpose is hereby granted without fee,
|
sl@0
|
9 |
* provided that the above copyright notice appear in all copies and
|
sl@0
|
10 |
* that both that copyright notice and this permission notice appear
|
sl@0
|
11 |
* in supporting documentation. Mark of the Unicorn makes no
|
sl@0
|
12 |
* representations about the suitability of this software for any
|
sl@0
|
13 |
* purpose. It is provided "as is" without express or implied warranty.
|
sl@0
|
14 |
|
sl@0
|
15 |
***********************************************************************************/
|
sl@0
|
16 |
#include "random_number.h"
|
sl@0
|
17 |
#include "Prefix.h"
|
sl@0
|
18 |
#if defined (EH_NEW_HEADERS)
|
sl@0
|
19 |
# include <functional>
|
sl@0
|
20 |
# include <cstdlib>
|
sl@0
|
21 |
#else
|
sl@0
|
22 |
# include <function.h>
|
sl@0
|
23 |
# include <stdlib.h>
|
sl@0
|
24 |
#endif
|
sl@0
|
25 |
|
sl@0
|
26 |
unsigned random_number( size_t range )
|
sl@0
|
27 |
{
|
sl@0
|
28 |
#if !defined( __SGI_STL )
|
sl@0
|
29 |
if (range == 0) return 0;
|
sl@0
|
30 |
return (unsigned)(EH_STD::rand() + EH_STD::rand()) % range;
|
sl@0
|
31 |
#else
|
sl@0
|
32 |
static EH_STD::subtractive_rng rnd;
|
sl@0
|
33 |
if (range==0) return 0;
|
sl@0
|
34 |
return rnd(range);
|
sl@0
|
35 |
#endif
|
sl@0
|
36 |
}
|
sl@0
|
37 |
|
sl@0
|
38 |
// default base for random container sizes
|
sl@0
|
39 |
unsigned random_base = 1000;
|