2024-10-20 10:39:09 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "global.h"
|
|
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
|
|
struct Random {
|
|
|
|
|
/* 00 */ u64 mRandomValue;
|
|
|
|
|
/* 08 */ u64 mFactor;
|
|
|
|
|
/* 10 */ u64 mAddend;
|
|
|
|
|
/* 18 */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generate a random number from 0 (inclusive) to `max` (exclusive)
|
|
|
|
|
*/
|
2025-07-21 19:09:56 +02:00
|
|
|
inline u32 Next(u32 min, u32 max) {
|
2024-10-20 10:39:09 +02:00
|
|
|
mRandomValue = mAddend + mFactor * mRandomValue;
|
2025-07-21 19:09:56 +02:00
|
|
|
u64 result = (mRandomValue >> 32) * (max - min);
|
|
|
|
|
return (result >> 32) + min;
|
2024-10-20 10:39:09 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-05-29 08:51:28 +02:00
|
|
|
extern Random gRandom;
|