Randomly select and display text

Hi there,

I have four text snippets "25% to $500 " , “50% to $1000” ,“100 to $300” and “200% to $100”. I would like to randomly select one of them and then be able to display it in a question.
Q. What would you use if prices increased by %randomlyselectedtext% ?

I have tried putting them in a roster, and using variables to randomly select a row, but then can’t get the text to display as a string. I would really appreciate any help or advice.


Hi Leonard,

I would put the 4 strings into string array in a String variable where some index ix selects one of them.
A second (Integer) variable ix should use Quest.IRnd() (the random no. assigned to the interview) to generate an integer between 1 and 4.
You can then use that string variable in your question text (using text substitution).


Dear Klaus, thank you for this useful feedback. I was thinking along those lines, but am struggling to do your step 1.
How would I define and index such an array?
I have tried: generate a variable, specify it as string and in the expression: Array.CreateInstance(typeof(string), “25”, “50”, “100”,“200”)

thanks once more for your help

new String[]{

where ix is between 0 and 3 since array indices are zero-based.

Klaus, thanks very much. I think I am one step away from getting it. I am now struggling with creating ix. As I understand, it needs to be created before the string variable.

I have tried to define ix as long integer with the following expression

But when I run the code you posted above for the string array, I get the error “cannot implicitly convert long to int”

thanks once more,

Try (int)Math.Floor(Quest.IRnd()*4)