Fix random number generation in Dice game
This commit is contained in:
parent
96cb799cc7
commit
3030919616
1 changed files with 2 additions and 2 deletions
|
|
@ -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, 7);
|
||||||
const won = gameResult === selectedNumber;
|
const won = gameResult === selectedNumber;
|
||||||
|
|
||||||
const multiplier = 3;
|
const multiplier = 3;
|
||||||
|
|
|
||||||
Reference in a new issue