-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow users to define their own random number generator
- Loading branch information
1 parent
6125561
commit 9ce1073
Showing
7 changed files
with
65 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright © 2024. GothicKit Contributors | ||
// SPDX-License-Identifier: MIT-Modern-Variant | ||
#include "_Internal.h" | ||
|
||
#include <stdlib.h> | ||
|
||
static uint32_t DmInt_defaultRng(void* ctx); | ||
|
||
static DmRng* DmGlob_rngCallback = DmInt_defaultRng; | ||
static void* DmGlob_rngContext = NULL; | ||
|
||
uint32_t Dm_rand(void) { | ||
return DmGlob_rngCallback(DmGlob_rngContext); | ||
} | ||
|
||
void Dm_setRandomNumberGenerator(DmRng* rng, void* ctx) { | ||
if (rng == NULL) { | ||
DmGlob_rngCallback = DmInt_defaultRng; | ||
DmGlob_rngContext = NULL; | ||
return; | ||
} | ||
|
||
DmGlob_rngCallback = rng; | ||
DmGlob_rngContext = ctx; | ||
} | ||
|
||
static uint32_t DmInt_defaultRng(void* ctx) { | ||
(void) ctx; | ||
return rand(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters