瀏覽代碼

Add SetRandomSeed(unsigned int seed) function (#1994)

Specifying a fixed seed for the random number generator is often
used in games for various reasons.

By adding an api function for seeding the random number generator
we solve two different problems regarding the seeding:

1) The underlying RNG implementation does not leak to client code
   (as would be the case if we called srand directly from the
   client code)
2) Seeding the RNG would be simple from other programming languages
   (especially in cases where calling libc functions is non-trivial)
pull/1995/head
Tommi Sinivuo 3 年之前
committed by GitHub
父節點
當前提交
3c55f067a8
沒有發現已知的金鑰在資料庫的簽署中 GPG Key ID: 4AEE18F83AFDEB23
共有 2 個文件被更改,包括 7 次插入0 次删除
  1. +6
    -0
      src/core.c
  2. +1
    -0
      src/raylib.h

+ 6
- 0
src/core.c 查看文件

@ -2669,6 +2669,12 @@ int GetRandomValue(int min, int max)
return (rand()%(abs(max - min) + 1) + min);
}
// Set the seed for the random number generator
void SetRandomSeed(unsigned int seed)
{
srand(seed);
}
// Check if the file exists
bool FileExists(const char *fileName)
{

+ 1
- 0
src/raylib.h 查看文件

@ -1009,6 +1009,7 @@ RLAPI double GetTime(void); // Get elapsed
// Misc. functions
RLAPI int GetRandomValue(int min, int max); // Get a random value between min and max (both included)
RLAPI void SetRandomSeed(unsigned int seed); // Set the seed for the random number generator
RLAPI void TakeScreenshot(const char *fileName); // Takes a screenshot of current screen (filename extension defines format)
RLAPI void SetConfigFlags(unsigned int flags); // Setup init configuration flags (view FLAGS)

Loading…
取消
儲存