#how do i give something a random chance

30 messages · Page 1 of 1 (latest)

olive breach
#

i want something to happen with a number here percent chance
how would i do that

echo copperBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

olive breach
#

rn my method is js if (Math.random() < 0.3) { *code here* }
but that doesnt work

#

it either always happens or never happens

stuck talon
#

try Math.random()

olive breach
#

i forgot the parenthesees in the codeblock sorry

#

i have the parrentheses in the actual code

#

and it is in startup scripts

astral tangle
#

I'm confused

olive breach
#

huh

#

what?

astral tangle
#

can you define math.random as a var before the if

#

output it to chat

#

then perform the if on that variable?

olive breach
#

math.random is a builtin thing

#

oh ok

astral tangle
#

yes

#

for example

#
var random = Math.random();
Utils.server.tell("Random: "+random);
if(random < 0.3) {
code
}
olive breach
#

thats exactly what i just wrote

astral tangle
#

no it is not

#

that will tel lyou in chat what exactly the number its generating

olive breach
#

no i meant i just typed in vscode

#

after you said that

astral tangle
#

oh lol

olive breach
#

ok ill try

astral tangle
#

@olive breachresults?

olive breach
#

wait im in class

olive breach
#

so it does work

#

guess i just got super unlucky in the 10 times i tried it