Skip to content

Commit

Permalink
feat: randomize 支持传入随机数种子,并返回所使用的随机数种子 (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
yixy-only authored Jun 8, 2024
1 parent 4c7c52c commit 818de81
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 4 additions & 2 deletions include/ege.h
Original file line number Diff line number Diff line change
Expand Up @@ -1354,8 +1354,10 @@ PVOID EGEAPI getProcfunc();
long EGEAPI getGraphicsVer();
float EGEAPI getfps();

void EGEAPI randomize();
unsigned int EGEAPI random(unsigned int n);
unsigned int EGEAPI randomize();
unsigned int EGEAPI randomize(unsigned int seed);

unsigned int EGEAPI random(unsigned int n = 0);
double EGEAPI randomf();


Expand Down
12 changes: 10 additions & 2 deletions src/random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,18 @@ extern double mtdrand()
return mtrand_help()(1.0);
}

void randomize()
uint32_t randomize()
{
static uint32_t add = 0;
mtsrand((uint32_t)time(NULL) + add++);
uint32_t seed = (uint32_t)time(NULL) + add++;
mtsrand(seed);
return seed;
}

uint32_t randomize(uint32_t seed)
{
mtsrand(seed);
return seed;
}

unsigned int random(unsigned int n)
Expand Down

0 comments on commit 818de81

Please sign in to comment.