Was wondering how to do random numbers

What Wick Editor Version are you using?
v1.19.3

Describe the Problem
I was wondering how to do random nums in js, as i want to make an easter egg that has a 1/25 chance of triggering, more specifically, a 1/25 chance of playing a different splash page sound in systematix os on start

Do you have a Wick Editor File that we can see? https://sites.google.com/view/systematix-os/downloads

1 Like

Have you tried what we have at the script reference?
Screen Shot 2021-03-20 at 3.20.59 PM

What I wrote in the picture, will give you an integer number from 1 to 10.

So for what you are looking for, you could do:

let myChance = random.integer(1,25);

if(myChance == 25) {
// do stuff
}
1 Like

I think it should actually be a triple equal since it’s JS. (idk maybe the editor understands double equal)

What about the other 1-24, how can i trigger that?

getRandomNum

if(num is 25) {
// 1 in 25 chance
} else {
// other 24 outcomes
}

I think “===” is used for differentiate the different kind of zeroes and their types…
For instance null is zero, undefined is zero.

(correction…)
https://codeburst.io/javascript-double-equals-vs-triple-equals-61d4ce5a121a

Example:
Here are editor’s js results:
Screen Shot 2021-03-20 at 3.38.51 PM

@awc95014
Good discussion, but anyways, we are save to use 25 == 25, it will return true.

Back in my day we used python, and only needed one equals

1 Like

=== will return false if the two aren’t of the same type
== may change their types accordingly and then compare them

1 Like

ty guys i got it working
Also i swapped it out for a 1/50 chance instead of 1/25
try your luck here

4 Likes