Merge pull request #91 from Lncvrt/main

Fix random number generation in Dice game
This commit is contained in:
Face 2025-07-15 18:12:06 +03:00 committed by GitHub
commit 9c98176851
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,7 +3,7 @@ import { error, json } from '@sveltejs/kit';
import { db } from '$lib/server/db'; import { db } from '$lib/server/db';
import { user } from '$lib/server/db/schema'; import { user } from '$lib/server/db/schema';
import { eq } from 'drizzle-orm'; import { eq } from 'drizzle-orm';
import { randomBytes } from 'crypto'; import { randomInt } from 'crypto';
import type { RequestHandler } from './$types'; import type { RequestHandler } from './$types';
interface DiceRequest { interface DiceRequest {
@ -54,7 +54,7 @@ export const POST: RequestHandler = async ({ request }) => {
throw new Error(`Insufficient funds. You need *${roundedAmount.toFixed(2)} but only have *${roundedBalance.toFixed(2)}`); throw new Error(`Insufficient funds. You need *${roundedAmount.toFixed(2)} but only have *${roundedBalance.toFixed(2)}`);
} }
const gameResult = Math.floor(randomBytes(1)[0] / 42.67) + 1; // This gives us a number between 1-6 const gameResult = randomInt(1, 6);
const won = gameResult === selectedNumber; const won = gameResult === selectedNumber;
const multiplier = 3; const multiplier = 3;