Skip to content

Commit e8dfa29

Browse files
committed
V1.4.7_1 - os::rand()
1 parent 094de4a commit e8dfa29

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

‎include/nodepp/posix/os.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ namespace nodepp { namespace os {
4141
inline int exec( string_t cmd ){ return ::system( cmd.get() ); }
4242

4343
inline int call( string_t cmd ){ return ::system( cmd.get() ); }
44+
45+
inline uchar_64 rand() {
46+
thread_local static uchar_64 seed = (uchar_64)&seed;
47+
seed ^= seed << 0x11;
48+
seed ^= seed >> 0x07;
49+
seed ^= seed << 0x0b; return seed;
50+
}
4451

4552
/*─······································································─*/
4653

‎include/nodepp/windows/os.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ namespace nodepp { namespace os {
5959

6060
inline int call( string_t cmd ){ return ::system( cmd.get() ); }
6161

62+
inline uchar_64 rand() {
63+
thread_local static uchar_64 seed = (uchar_64)&seed;
64+
seed ^= seed << 0x11;
65+
seed ^= seed >> 0x07;
66+
seed ^= seed << 0x0b; return seed;
67+
}
68+
6269
/*─······································································─*/
6370

6471
inline uint pid(){ return GetCurrentProcessId(); }

‎main.cpp‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
#include <nodepp/nodepp.h>
2+
#include <nodepp/timer.h>
23

34
using namespace nodepp;
45

56
/*────────────────────────────────────────────────────────────────────────────*/
67

78
void onMain() {
89

9-
handler_t<int> hdl;
10+
console::log( encoder::hex::atob( 17 ) );
11+
console::log( encoder::hex::atob( 7 ) );
12+
console::log( encoder::hex::atob( 13 ) );
1013

11-
auto hdl1 = hdl.create(); hdl.update( hdl1, 10 );
12-
auto hdl2 = hdl.create(); hdl.update( hdl2, 20 );
13-
auto hdl3 = hdl.create(); hdl.update( hdl3, 30 );
14-
auto hdl4 = hdl.create(); hdl.update( hdl4, 40 );
15-
16-
hdl.get_queue().swap(
17-
hdl.get_queue().first(),
18-
hdl.get_queue().last ()
19-
);
20-
21-
console::log( hdl.read( hdl1 )[0] );
22-
console::log( hdl.read( hdl4 )[0] );
14+
timer::add([=](){
15+
console::log( os::rand() );
16+
return 1; }, 1000 );
2317

2418
}
2519

0 commit comments

Comments
 (0)