Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
dineshmdane
Partner - Contributor III
Partner - Contributor III

Creating random numbers on button click

Hi all,

Want to create random numbers on clicking a button.

Example :

clicking a button produce a number '3' and clicking the same button again produce another number '7' and so on.within the limit of 20.

Kindly awaiting for your response

Regards,

Dinesh M

1 Solution

Accepted Solutions
sasiparupudi1
Master III
Master III

May be use a piece of macro

sub Random

set vRand = ActiveDocument.GetVariable("vRand")

x= rnd*20

vRand.setContent x,True

End sub

View solution in original post

10 Replies
swuehl
MVP
MVP

Maybe create an External - Set Variable action in the button properties and set a variable value to

=Ceil(RAND()*20)     

marcus_sommer

Maybe this is helpful: Re: Generate 6 different random numbers

- Marcus

sunny_talwar

Do you know why it wouldn't work for me in the attached file. Seems like the value for Rand() just doesn't want to change

adamdavi3s
Master
Master

It's weird but maybe it only recalculates when something changes?

I changed it to rand*now() and clicking the button does then work

swuehl
MVP
MVP

Seems like some kind of caching is kicking in.

We may need to force Qlik to reevaluate the expression:

=Ceil(RAND()*100) +0*Now(1)

(Sometimes it takes more than 1 click to change)

sasiparupudi1
Master III
Master III

May be use a piece of macro

sub Random

set vRand = ActiveDocument.GetVariable("vRand")

x= rnd*20

vRand.setContent x,True

End sub

dineshmdane
Partner - Contributor III
Partner - Contributor III
Author

Ya Sunny on button click it will not change.It will change only on reload.

Thank you.

dineshmdane
Partner - Contributor III
Partner - Contributor III
Author

Thanks you Stefan it is working as you said it takes more that one click sometimes .

Any other method to change the value on one click.

dineshmdane
Partner - Contributor III
Partner - Contributor III
Author

Thank  you Sasidhar. It is working.