Can you set a random number to not be zero

I am trying to create a random number in the script, this one is in a graph. I want my numbers to range from -5 to 5, but not be zero. Is there a way to make it skip 0?

Here is what I have, but 0 is a possible value:


1 Like

You can generate two numbers:
Integer between 1 and 5
1 or 2

Use the first integer as the base
If the second integer is 1 make it positive
If the second integer is 2 make it negative

I like to create a numberList of the possible random numbers I want. Then I generate an index to choose a number from that list. See example here… Specific Random Number (delete) • Activity Builder by Desmos


Thats a great solution!

Thanks, I was using something like this, but didn’t know if there was a better way.

I created a and b, then made a = 1 or 2 and b = 1 to 5.
Then I used (-1)^a*b.

1 Like

Thanks! I like that solution too.

I’ve been using the code snippet below to do this all in one step without declaring any extra variables. It’s a little uglier, but if you keep it handy to copy/paste it’s worth it.

number(“a”): numericValue("(-1)^${,1)}*${,5)}")


Ooh I like that. I can fit it all on one line & I don’t have a bunch of extra variables floating around. Thanks for sharing!!