corbin
(Carla Corbin)
April 16, 2019, 6:15pm
1
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:
rand=randomGenerator()
number(“a”): rand.int(-5,5)
1 Like
JayChow
(Jay Chow)
April 16, 2019, 6:26pm
2
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
mxepstein
(greg epstein)
April 16, 2019, 6:50pm
3
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
2 Likes
corbin
(Carla Corbin)
April 16, 2019, 8:34pm
5
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
corbin
(Carla Corbin)
April 16, 2019, 8:37pm
6
Thanks! I like that solution too.
Shaun
(Shaun Kelly)
April 17, 2019, 3:30am
7
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.
rand=randomGenerator()
number(“a”): numericValue("(-1)^${rand.int(0,1)}*${rand.int(1,5)}")
4 Likes
corbin
(Carla Corbin)
April 17, 2019, 10:13am
8
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!!