[Home] >  Random >  Generate a random sign

Generate a random sign

JavaScript version

const randomSign = () => (Math.random() >= 0.5 ? 1 : -1);

TypeScript version

const randomSign = (): number => (Math.random() >= 0.5 ? 1 : -1);