chore: improve distribution of rewardSeed (#1831)
This was previously not ideal due to float imprecision, but now it's 64 bits and there's enough entropy for all of them. Reviewed-on: OpenWF/SpaceNinjaServer#1831 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									fd7f4c9e92
								
							
						
					
					
						commit
						0b75757277
					
				@ -390,7 +390,7 @@ MailboxSchema.set("toJSON", {
 | 
			
		||||
 | 
			
		||||
const DuviriInfoSchema = new Schema<IDuviriInfo>(
 | 
			
		||||
    {
 | 
			
		||||
        Seed: Number,
 | 
			
		||||
        Seed: BigInt,
 | 
			
		||||
        NumCompletions: { type: Number, default: 0 }
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
@ -120,10 +120,15 @@ 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;
 | 
			
		||||
        seed -= 1n;
 | 
			
		||||
    }
 | 
			
		||||
    return seed;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
//TODO: RawUpgrades might need to return a LastAdded
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user