chore: improve distribution of rewardSeed
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:
parent
100aefcee4
commit
9bb6ffeb65
@ -390,7 +390,7 @@ MailboxSchema.set("toJSON", {
|
|||||||
|
|
||||||
const DuviriInfoSchema = new Schema<IDuviriInfo>(
|
const DuviriInfoSchema = new Schema<IDuviriInfo>(
|
||||||
{
|
{
|
||||||
Seed: Number,
|
Seed: BigInt,
|
||||||
NumCompletions: { type: Number, default: 0 }
|
NumCompletions: { type: Number, default: 0 }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -120,10 +120,14 @@ export const createInventory = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const generateRewardSeed = (): number => {
|
export const generateRewardSeed = (): bigint => {
|
||||||
const min = -Number.MAX_SAFE_INTEGER;
|
const hiDword = getRandomInt(0, 0x7fffffff);
|
||||||
const max = Number.MAX_SAFE_INTEGER;
|
const loDword = getRandomInt(0, 0xffffffff);
|
||||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
let seed = (BigInt(hiDword) << 32n) | BigInt(loDword);
|
||||||
|
if (Math.random() < 0.5) {
|
||||||
|
seed *= -1n;
|
||||||
|
}
|
||||||
|
return seed;
|
||||||
};
|
};
|
||||||
|
|
||||||
//TODO: RawUpgrades might need to return a LastAdded
|
//TODO: RawUpgrades might need to return a LastAdded
|
||||||
|
@ -134,7 +134,7 @@ export const equipmentKeys = [
|
|||||||
export type TEquipmentKey = (typeof equipmentKeys)[number];
|
export type TEquipmentKey = (typeof equipmentKeys)[number];
|
||||||
|
|
||||||
export interface IDuviriInfo {
|
export interface IDuviriInfo {
|
||||||
Seed: number;
|
Seed: bigint;
|
||||||
NumCompletions: number;
|
NumCompletions: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,7 +202,7 @@ export interface IInventoryClient extends IDailyAffiliations, InventoryClientEqu
|
|||||||
Mailbox?: IMailboxClient;
|
Mailbox?: IMailboxClient;
|
||||||
SubscribedToEmails: number;
|
SubscribedToEmails: number;
|
||||||
Created: IMongoDate;
|
Created: IMongoDate;
|
||||||
RewardSeed: number | bigint;
|
RewardSeed: bigint;
|
||||||
RegularCredits: number;
|
RegularCredits: number;
|
||||||
PremiumCredits: number;
|
PremiumCredits: number;
|
||||||
PremiumCreditsFree: number;
|
PremiumCreditsFree: number;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user