7 Replies Latest reply: Apr 14, 2016 11:08 AM by John Blomqvist

# How can I generate Random negative and Positive values for a field?

Hi all,

Let's say I have a following table like this:

OrderIDValue
133.44
288.99
355.99
4-157.08
545.87
6-34.99

How can I generate random Negative and Positive values for the Value field using the rand() function?

• ###### Re: How can I generate Random negative and Positive values for a field?

Try this may be:

Table:

LOAD Round(Rand() * (200+200) -200, 0.01) as RandValue

AutoGenerate 1000;

UPDATE: This will generate 1000 values between -200 and 200

UPDATE: Stole the idea from here -> How to create Random number within specific range in Qlikview/Qliksense in script ?

• ###### Re: How can I generate Random negative and Positive values for a field?

For your specific table, you can do this:

Round(Rand() * (200+200) -200, 0.01) as Value

FROM Source;

• ###### Re: How can I generate Random negative and Positive values for a field?

Hi Sunny,

How can I do it so the range is no less than 700 and no higher than 200?

• ###### Re: How can I generate Random negative and Positive values for a field?

May be this:

Round(Rand() * (200+700) -700, 0.01) as Value

FROM Source;

Assuming you meant no less than -700

• ###### Re: How can I generate Random negative and Positive values for a field?

Thank you buddy

• ###### Re: How can I generate Random negative and Positive values for a field?

John Blomqvist wrote:

Hi Sunny,

How can I do it so the range is no less than 700 and no higher than 200?

In this case you're talking about a bandwidth of 900, offset by -700, assuming Sunny is correct and you mean -700>x<200

Let vOffset = -700;

• ###### Re: How can I generate Random negative and Positive values for a field?

Hello John,

You could try something like

LOAD 100* (Rand() * sign(Rand() - .5)) AS POS_NEG AUTOGENERATE(10);

For 10 randoms between 100 to -100