Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
godot
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
community
godot
Commits
6280be46
Commit
6280be46
authored
Mar 17, 2019
by
Chaosus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Properly setup seed in RNG
parent
df7d3708
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
5 deletions
+15
-5
random_pcg.cpp
core/math/random_pcg.cpp
+1
-2
random_pcg.h
core/math/random_pcg.h
+3
-3
pcg.cpp
thirdparty/misc/pcg.cpp
+10
-0
pcg.h
thirdparty/misc/pcg.h
+1
-0
No files found.
core/math/random_pcg.cpp
View file @
6280be46
...
...
@@ -34,8 +34,7 @@
RandomPCG
::
RandomPCG
(
uint64_t
p_seed
,
uint64_t
p_inc
)
:
pcg
(),
current_seed
(
DEFAULT_SEED
)
{
pcg
.
inc
=
p_inc
;
current_inc
(
p_inc
)
{
seed
(
p_seed
);
}
...
...
core/math/random_pcg.h
View file @
6280be46
...
...
@@ -38,18 +38,18 @@
class
RandomPCG
{
pcg32_random_t
pcg
;
uint64_t
current_seed
;
// seed with this to get the same state
uint64_t
current_inc
;
public
:
static
const
uint64_t
DEFAULT_SEED
=
12047754176567800795U
;
static
const
uint64_t
DEFAULT_INC
=
PCG_DEFAULT_INC_64
;
static
const
uint64_t
RANDOM_MAX
=
0xFFFFFFFF
;
RandomPCG
(
uint64_t
p_seed
=
DEFAULT_SEED
,
uint64_t
p_inc
=
PCG_DEFAULT_INC_64
);
RandomPCG
(
uint64_t
p_seed
=
DEFAULT_SEED
,
uint64_t
p_inc
=
DEFAULT_INC
);
_FORCE_INLINE_
void
seed
(
uint64_t
p_seed
)
{
current_seed
=
p_seed
;
pcg
.
state
=
p_seed
;
pcg32_random_r
(
&
pcg
);
// Force changing internal state to avoid initial 0
pcg32_srandom_r
(
&
pcg
,
current_seed
,
current_inc
);
}
_FORCE_INLINE_
uint64_t
get_seed
()
{
return
current_seed
;
}
...
...
thirdparty/misc/pcg.cpp
View file @
6280be46
...
...
@@ -13,3 +13,13 @@ uint32_t pcg32_random_r(pcg32_random_t* rng)
uint32_t
rot
=
oldstate
>>
59u
;
return
(
xorshifted
>>
rot
)
|
(
xorshifted
<<
((
-
rot
)
&
31
));
}
// Source from http://www.pcg-random.org/downloads/pcg-c-basic-0.9.zip
void
pcg32_srandom_r
(
pcg32_random_t
*
rng
,
uint64_t
initstate
,
uint64_t
initseq
)
{
rng
->
state
=
0U
;
rng
->
inc
=
(
initseq
<<
1u
)
|
1u
;
pcg32_random_r
(
rng
);
rng
->
state
+=
initstate
;
pcg32_random_r
(
rng
);
}
thirdparty/misc/pcg.h
View file @
6280be46
...
...
@@ -10,5 +10,6 @@
typedef
struct
{
uint64_t
state
;
uint64_t
inc
;
}
pcg32_random_t
;
uint32_t
pcg32_random_r
(
pcg32_random_t
*
rng
);
void
pcg32_srandom_r
(
pcg32_random_t
*
rng
,
uint64_t
initstate
,
uint64_t
initseq
);
#endif // RANDOM_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment