chore: improve distribution of rewardSeed
All checks were successful
Build / build (pull_request) Successful in 49s
Build / build (push) Successful in 1m33s

This was previously not ideal due to float imprecision, but now it's 64 bits and there's enough entropy for all of them.
This commit is contained in:
Sainan 2025-04-25 08:10:05 +02:00
parent 100aefcee4
commit 9bb6ffeb65
3 changed files with 11 additions and 7 deletions

View File

@ -390,7 +390,7 @@ MailboxSchema.set("toJSON", {
const DuviriInfoSchema = new Schema<IDuviriInfo>(
{
Seed: Number,
Seed: BigInt,
NumCompletions: { type: Number, default: 0 }
},
{

View File

@ -120,10 +120,14 @@ export const createInventory = async (
}
};
export const generateRewardSeed = (): number => {
const min = -Number.MAX_SAFE_INTEGER;
const max = Number.MAX_SAFE_INTEGER;
return Math.floor(Math.random() * (max - min + 1)) + min;
export const generateRewardSeed = (): bigint => {
const hiDword = getRandomInt(0, 0x7fffffff);
const loDword = getRandomInt(0, 0xffffffff);
let seed = (BigInt(hiDword) << 32n) | BigInt(loDword);
if (Math.random() < 0.5) {
seed *= -1n;
}
return seed;
};
//TODO: RawUpgrades might need to return a LastAdded

View File

@ -134,7 +134,7 @@ export const equipmentKeys = [
export type TEquipmentKey = (typeof equipmentKeys)[number];
export interface IDuviriInfo {
Seed: number;
Seed: bigint;
NumCompletions: number;
}
@ -202,7 +202,7 @@ export interface IInventoryClient extends IDailyAffiliations, InventoryClientEqu
Mailbox?: IMailboxClient;
SubscribedToEmails: number;
Created: IMongoDate;
RewardSeed: number | bigint;
RewardSeed: bigint;
RegularCredits: number;
PremiumCredits: number;
PremiumCreditsFree: number;