Page 1 of 1

ValueSet.Randomize Function

Posted: September 27th, 2023, 8:16 pm
by Vicmarfe
Hi team:
I use the ValueSet.Randomize function in a question's logic, to randomize its ValueSet, as follows:
VariableName.VS1.Randomize(Exclude(8,9));
However, every time the question is displayed, the values ​​are always displayed from 1 to 9, they are only becomes randomly when moving back from the next field.
How can I get them to be displayed randomly from the first time the question appears on the device screen, and in all cases?
Thanks in advance.

Vicmar

Re: ValueSet.Randomize Function

Posted: September 28th, 2023, 8:35 am
by Gregory Martin
Random numbers in the computer world are rarely truly random, as an algorithm determines in what order numbers appear. What you need to do to get randomness in the sequence is to call the seed function: https://www.csprousers.org/help/CSPro/s ... ction.html

A common procedure is to "seed" the random number generator with the time, like this:
seed(timestamp());
If you do this at the beginning of your program, you will get different random numbers throughout.

Re: ValueSet.Randomize Function

Posted: September 28th, 2023, 8:23 pm
by Vicmarfe
Thanks Gregory
Now randomize works as we need.
However, we have an additional problem, we use the following code to remove the option selected in the previous question (P2);

PROC P2A
Preproc
ValueSet r=P2A_VS1;
r.remove(P2);
setvalueset(P2A,r);
seed(timestamp());
P2a_VS1.Randomize(Exclude(8,9));


Options are always displayed from 1 to 9, never random. Is it possible to randomize this question?

Best.

Re: ValueSet.Randomize Function

Posted: September 29th, 2023, 5:09 pm
by Gregory Martin
You're setting a custom value set for P2A, so it won't be using P2A_VS1. You should randomize r:
PROC P2A
Preproc
ValueSet
r=P2A_VS1;
r.remove(P2);
seed(timestamp());
r.Randomize(Exclude(8,9));
setvalueset(P2A,r);

Re: ValueSet.Randomize Function

Posted: September 29th, 2023, 8:34 pm
by Vicmarfe
Thanks Gregory
Now everything is working fine
Your help has been very useful.

Happy weekend.