[Home] >  Misc >  Emulate a dice throw

Emulate a dice throw

JavaScript version

const throwdice = () => ~~(Math.random() * 6) + 1;

TypeScript version

const throwdice = (): number => ~~(Math.random() * 6) + 1;

Examples

throwdice(); // 4
throwdice(); // 1
throwdice(); // 6