Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Random Number Between -1 and 1

naeema
6 - Meteoroid

Hi,

 

I am wondering how to generate a random number between negative and positive one.

 

I've found out how to generate a number between 0 and 1. But in terms of a negative number I've had no luck.

 

Any advice?                     

3 REPLIES 3
jdunkerley79
ACE Emeritus
ACE Emeritus

Use a formula tool with expression:

 

RAND()*2-1

Rand makes a random number between 0 and 1. Then you can double and shift.

naeema
6 - Meteoroid

I have decided to use two random Values, the second random value will decide whether the first random value is positive or negative (first random value is between 0 and 1).

 

Any better solutions?

martensite
8 - Asteroid

Hi,

 

If you only want to show these values: -1, 0 and 1. You can use the following formula:

 

SWITCH(RandInt(2),1,
0,-1,
1,0,
2,1)

Labels
Top Solution Authors