History

update to ck_random()

Ge Wang committed 3 years ago

Commit 2f2c9671 parent 170b70a7 files · +74 −75Browse files

Showing the changes to src/core/util_math.cpp (1 of 7 files). Show all

Unified · Split

src/core/util_math.cpp+11−12
@@ -68,31 +68,30 @@ double trunc( double a ) · 67 unmodified lines
68#endif68#endif
69 69
70 70
71#ifndef __OLDSCHOOL_RANDOM__71//-----------------------------------------------------------------------------
72 72#ifndef __OLDSCHOOL_RANDOM__ // not using old school, pre-c++11 compatibility
73//-----------------------------------------------------------------------------73//-----------------------------------------------------------------------------
74// name: ck_random() and ck_srandom()74// name: ck_random() and ck_srandom()
75// desc: chuck wrappers for random number generators | 1.4.2.0 (ge)75// desc: chuck wrappers for random number generators
76// 1.5.0.1 (ge) using mt19937 (requires c++11)
76//-----------------------------------------------------------------------------77//-----------------------------------------------------------------------------
77static std::mt19937 g_ck_global_rng;78static std::mt19937 g_ck_global_rng;
78t_CKINT ck_random() { return g_ck_globa_rng() % CK_RANDOM_MAX; }79t_CKINT ck_random() { return g_ck_global_rng() % CK_RANDOM_MAX; }
79void ck_srandom( unsigned s ) { g_ck_global_rng.seed(s); }80void ck_srandom( unsigned s ) { g_ck_global_rng.seed(s); }
80 81//-----------------------------------------------------------------------------
81
82#else // using old school random (pre-c++11)82#else // using old school random (pre-c++11)
83
84//-----------------------------------------------------------------------------83//-----------------------------------------------------------------------------
85// name: ck_random() and ck_srandom()84// name: ck_random() and ck_srandom()
86// desc: chuck wrappers for random number generators | 1.4.2.0 (ge)85// desc: chuck wrappers for random number generators | 1.4.2.0 (ge)
87//-----------------------------------------------------------------------------86//-----------------------------------------------------------------------------
88#ifndef __PLATFORM_WIN32__87#ifndef __PLATFORM_WIN32__
89t_CKINT ck_random() { return random(); }88 t_CKINT ck_random() { return random(); }
90void ck_srandom( unsigned s ) { srandom( s ); }89 void ck_srandom( unsigned s ) { srandom( s ); }
91#else // __WINDOWS_DS__90#else // __WINDOWS_DS__
92t_CKINT ck_random() { return rand(); }91 t_CKINT ck_random() { return rand(); }
93void ck_srandom( unsigned s ) { srand( s ); }92 void ck_srandom( unsigned s ) { srand( s ); }
94
95#endif93#endif
94//-----------------------------------------------------------------------------
96#endif // __OLDSCHOOL_RANDOM__95#endif // __OLDSCHOOL_RANDOM__
97 96
98 97

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t