Skip to content

Commit

Permalink
Added math function (rand between range)
Browse files Browse the repository at this point in the history
  • Loading branch information
iWas-Coder committed Jan 18, 2025
1 parent f39824e commit 6f6697a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion carbon.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ typedef struct {
} CBN_Row;

CARBON_API void carbon_math_srand(u64 seed);
CARBON_API int carbon_math_rand(void);
CARBON_API i32 carbon_math_rand(void);
CARBON_API i32 carbon_math_rand_between(i32 min, i32 max);
CARBON_API f32 carbon_math_randf(void);
CARBON_API void carbon_math_mt19937_64_srand(u64 seed);
CARBON_API u64 carbon_math_mt19937_64_rand(void);
Expand Down
4 changes: 4 additions & 0 deletions src/carbon_math.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ i32 carbon_math_rand(void) {
return carbon_math__rand_seed >> 33;
}

i32 carbon_math_rand_between(i32 min, i32 max) {
return carbon_math_rand() % (max + 1 - min) + min;
}

f32 carbon_math_randf(void) {
return (f32) carbon_math_rand() / (f32) CARBON_RAND_MAX;
}
Expand Down

0 comments on commit 6f6697a

Please sign in to comment.