Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
illuna-minetest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
illuna-minetest
Commits
cd1d625a
Commit
cd1d625a
authored
9 years ago
by
kwolekr
Browse files
Options
Downloads
Patches
Plain Diff
Replace PRNG assertions with PrngException
parent
732eb72a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/exceptions.h
+5
-0
5 additions, 0 deletions
src/exceptions.h
src/noise.cpp
+3
-1
3 additions, 1 deletion
src/noise.cpp
src/noise.h
+5
-3
5 additions, 3 deletions
src/noise.h
with
13 additions
and
4 deletions
src/exceptions.h
+
5
−
0
View file @
cd1d625a
...
...
@@ -120,6 +120,11 @@ class ClientStateError : public BaseException {
ClientStateError
(
std
::
string
s
)
:
BaseException
(
s
)
{}
};
class
PrngException
:
public
BaseException
{
public:
PrngException
(
std
::
string
s
)
:
BaseException
(
s
)
{}
};
/*
Some "old-style" interrupts:
*/
...
...
This diff is collapsed.
Click to expand it.
src/noise.cpp
+
3
−
1
View file @
cd1d625a
...
...
@@ -115,7 +115,9 @@ u32 PcgRandom::range(u32 bound)
s32
PcgRandom
::
range
(
s32
min
,
s32
max
)
{
assert
(
max
>=
min
);
if
(
max
<
min
)
throw
PrngException
(
"Invalid range (max < min)"
);
u32
bound
=
max
-
min
+
1
;
return
range
(
bound
)
+
min
;
}
...
...
This diff is collapsed.
Click to expand it.
src/noise.h
+
5
−
3
View file @
cd1d625a
...
...
@@ -26,8 +26,8 @@
#ifndef NOISE_HEADER
#define NOISE_HEADER
#include
"debug.h"
#include
"irr_v3d.h"
#include
"exceptions.h"
#include
"util/string.h"
extern
FlagDesc
flagdesc_noiseparams
[];
...
...
@@ -56,14 +56,16 @@ class PseudoRandom {
inline
int
range
(
int
min
,
int
max
)
{
assert
(
max
>=
min
);
if
(
max
<
min
)
throw
PrngException
(
"Invalid range (max < min)"
);
/*
Here, we ensure the range is not too large relative to RANDOM_MAX,
as otherwise the effects of bias would become noticable. Unlike
PcgRandom, we cannot modify this RNG's range as it would change the
output of this RNG for reverse compatibility.
*/
assert
((
u32
)(
max
-
min
)
<=
(
RANDOM_RANGE
+
1
)
/
10
);
if
((
u32
)(
max
-
min
)
>
(
RANDOM_RANGE
+
1
)
/
10
)
throw
PrngException
(
"Range too large"
);
return
(
next
()
%
(
max
-
min
+
1
))
+
min
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment