1
///////////////////////////////////////////////////////////////////////////
3
// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
6
// All rights reserved.
8
// Redistribution and use in source and binary forms, with or without
9
// modification, are permitted provided that the following conditions are
11
// * Redistributions of source code must retain the above copyright
12
// notice, this list of conditions and the following disclaimer.
13
// * Redistributions in binary form must reproduce the above
14
// copyright notice, this list of conditions and the following disclaimer
15
// in the documentation and/or other materials provided with the
17
// * Neither the name of Industrial Light & Magic nor the names of
18
// its contributors may be used to endorse or promote products derived
19
// from this software without specific prior written permission.
21
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
///////////////////////////////////////////////////////////////////////////
37
#include <testRandom.h>
38
#include <ImathRandom.h>
57
// Test if the values, and the differences between
58
// successive values, are evenly distributed.
67
int *d = &diffs[N + 2];
69
for (int i = 0; i <= N; ++i)
72
for (int i = -N; i <= N; ++i)
78
for (int i = 0; i < M * N; ++i)
80
float r = rand.nextf (0.0, 1.0);
81
float diff = r - previous;
85
d[Imath::floor (diff * N + 0.5)] += 1;
88
cout << " values" << endl;
90
for (int i = 0; i < N; ++i)
92
// cout << setw (4) << i << ' ' << setw(6) << v[i] << ' ';
93
assert (abs (v[i] - M) < 0.01 * M);
95
// for (int j = 0; j < v[i] * 60 / M; ++j)
103
cout << " differences between successive values" << endl;
105
for (int i = -N; i <= N; ++i)
107
// cout << setw (4) << i << ' ' << setw (6) << d[i] << ' ';
108
assert (abs ((N - abs (i)) * M / N - d[i]) < 0.05 * M);
110
// for (int j = 0; j < d[i] * 60 / M; ++j)
118
template <class Rand>
126
for (int i = 0; i <= N; ++i)
131
for (int i = 0; i < M * N; ++i)
133
Imath::V3f p = Imath::solidSphereRand<Imath::V3f> (rand);
134
float l = p.length();
135
v[Imath::floor (l * N)] += 1;
137
assert (l < 1.00001);
140
for (int i = 0; i < N; ++i)
145
template <class Rand>
149
const int M = 100000;
152
for (int i = 0; i < M; ++i)
154
Imath::V3f p = Imath::hollowSphereRand<Imath::V3f> (rand);
155
float l = p.length();
157
assert (abs (l - 1) < 0.00001);
168
cout << "Testing random number generators" << endl;
170
cout << "Rand32" << endl;
171
testGenerator<Imath::Rand32>();
173
cout << "Rand48" << endl;
174
testGenerator<Imath::Rand32>();
176
cout << "solidSphereRand()" << endl;
177
testSolidSphere<Imath::Rand32>();
179
cout << "hollowSphereRand()" << endl;
180
testHollowSphere<Imath::Rand32>();
182
cout << "ok\n" << endl;