Add comma(s) to randomly generated number


Author
Message
Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 109K
wmfang - 9/10/2025
Dave - 9/10/2025
wmfang - 9/10/2025
Dave - 9/10/2025
wmfang - 9/10/2025
Dave - 9/10/2025
wmfang - 9/9/2025
I would like to display text that includes a random number between 10000 and 50000, but for the text to include the commas so that it reads as "10,000 followers" and "50,000 followers".

This is what I currently have:

<text followersText>
/ items = ("<% round(rand(10000, 50000)) %> followers")
/ position = (20%, 65%)
/ fontstyle = ("Arial", 2%, false, false, false, false, 5, 0)
/ color = steelblue
/ halign = left
</text>

Thanks!

<text followersText>
/ items = ("<%subString(values.nFollowers, 0, 2)%>,<%subString(values.nFollowers, 2, 3)%> followers")
/ position = (20%, 65%)
/ fontstyle = ("Arial", 2%, false, false, false, false, 5, 0)
/ color = steelblue
/ halign = left
</text>

<values>
/ nFollowers = null
</values>

<trial exampleTrial>
/ onTrialBegin = {
    values.nFollowers = round(rand(10000, 50000));
}
/ stimulusFrames = [1=followersText]
/ validResponse = (" ")
</trial>

Would this also work? Why does values need to first be null? Thanks!

<values>
/ nFollowers = round(rand(10000, 50000));
</values>

<text followersText>
/ items = ("<%subString(values.nFollowers, 0, 2)%>,<%subString(values.nFollowers, 2, 3)%> followers")
/ position = (20%, 65%)
/ fontstyle = ("Arial", 2%, false, false, false, false, 5, 0)
/ color = steelblue
/ halign = left
</text>

<surveypage high_social_ID>
/ questions = [1=backgroundImage_ID_1; 2=profileImage; 3=slider_bar_social_1]
/ stimulusframes = [
1=background_outer;
2=background;
3=nameImage;
4=followersText;
5=connectionsText_high;
6=locationText_ID;
7=dot_high]
/ nextlabel = "Next"
/ showpagenumbers = false
/ recorddata = true
/ navigationbuttonfontstyle = ("Arial", 12pt, false)
</surveypage>

<block socialONLY>
/ trials = [
1-8=noreplacenorepeat(
high_social_AR,
high_social_SC,
high_social_TN,
high_social_ID,
low_social_AR,
low_social_SC,
low_social_TN,
low_social_ID)
]
</block>


You can do this, if you don't want the value (a variable) to ever change. Then the round(rand()) expression is evaluated a single time when the script is parsted, and whatever the result is the value the variable will have. Usually, however, you'll want variables to change in specific ways at speciffic times, so you initialize (see below) and set it to whatever you need later.

> Why does values need to first be null?

It doesn't have to. It's a normal way to initialize a variable whose value is to be determined later.

Got it. Thanks! How do I make it so that the value changes with each surveypage?

You set the value to a new one /onTrialBegin in the <surveypage>, just like I showed in the example code I gave you.

How do I make it so that the <data> stores the value for each surveypage in a column? Thanks so much

First, you need to run your surveypages via blocks, not survey elements.

Second, you define a data element with everything you want logged, and you include the variable as a column there.

https://www.millisecond.com/support/docs/current/html/language/attributes/columns.htm

More generally, you may benefit from working through the Programmer's Manual:
https://www.millisecond.com/support/Inquisit%20Programmer's%20Manual.pdf


wmfang
wmfang
Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)
Group: Forum Members
Posts: 20, Visits: 64
Dave - 9/10/2025
wmfang - 9/10/2025
Dave - 9/10/2025
wmfang - 9/10/2025
Dave - 9/10/2025
wmfang - 9/9/2025
I would like to display text that includes a random number between 10000 and 50000, but for the text to include the commas so that it reads as "10,000 followers" and "50,000 followers".

This is what I currently have:

<text followersText>
/ items = ("<% round(rand(10000, 50000)) %> followers")
/ position = (20%, 65%)
/ fontstyle = ("Arial", 2%, false, false, false, false, 5, 0)
/ color = steelblue
/ halign = left
</text>

Thanks!

<text followersText>
/ items = ("<%subString(values.nFollowers, 0, 2)%>,<%subString(values.nFollowers, 2, 3)%> followers")
/ position = (20%, 65%)
/ fontstyle = ("Arial", 2%, false, false, false, false, 5, 0)
/ color = steelblue
/ halign = left
</text>

<values>
/ nFollowers = null
</values>

<trial exampleTrial>
/ onTrialBegin = {
    values.nFollowers = round(rand(10000, 50000));
}
/ stimulusFrames = [1=followersText]
/ validResponse = (" ")
</trial>

Would this also work? Why does values need to first be null? Thanks!

<values>
/ nFollowers = round(rand(10000, 50000));
</values>

<text followersText>
/ items = ("<%subString(values.nFollowers, 0, 2)%>,<%subString(values.nFollowers, 2, 3)%> followers")
/ position = (20%, 65%)
/ fontstyle = ("Arial", 2%, false, false, false, false, 5, 0)
/ color = steelblue
/ halign = left
</text>

<surveypage high_social_ID>
/ questions = [1=backgroundImage_ID_1; 2=profileImage; 3=slider_bar_social_1]
/ stimulusframes = [
1=background_outer;
2=background;
3=nameImage;
4=followersText;
5=connectionsText_high;
6=locationText_ID;
7=dot_high]
/ nextlabel = "Next"
/ showpagenumbers = false
/ recorddata = true
/ navigationbuttonfontstyle = ("Arial", 12pt, false)
</surveypage>

<block socialONLY>
/ trials = [
1-8=noreplacenorepeat(
high_social_AR,
high_social_SC,
high_social_TN,
high_social_ID,
low_social_AR,
low_social_SC,
low_social_TN,
low_social_ID)
]
</block>


You can do this, if you don't want the value (a variable) to ever change. Then the round(rand()) expression is evaluated a single time when the script is parsted, and whatever the result is the value the variable will have. Usually, however, you'll want variables to change in specific ways at speciffic times, so you initialize (see below) and set it to whatever you need later.

> Why does values need to first be null?

It doesn't have to. It's a normal way to initialize a variable whose value is to be determined later.

Got it. Thanks! How do I make it so that the value changes with each surveypage?

You set the value to a new one /onTrialBegin in the <surveypage>, just like I showed in the example code I gave you.

How do I make it so that the <data> stores the value for each surveypage in a column? Thanks so much
Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 109K
wmfang - 9/10/2025
Dave - 9/10/2025
wmfang - 9/10/2025
Dave - 9/10/2025
wmfang - 9/9/2025
I would like to display text that includes a random number between 10000 and 50000, but for the text to include the commas so that it reads as "10,000 followers" and "50,000 followers".

This is what I currently have:

<text followersText>
/ items = ("<% round(rand(10000, 50000)) %> followers")
/ position = (20%, 65%)
/ fontstyle = ("Arial", 2%, false, false, false, false, 5, 0)
/ color = steelblue
/ halign = left
</text>

Thanks!

<text followersText>
/ items = ("<%subString(values.nFollowers, 0, 2)%>,<%subString(values.nFollowers, 2, 3)%> followers")
/ position = (20%, 65%)
/ fontstyle = ("Arial", 2%, false, false, false, false, 5, 0)
/ color = steelblue
/ halign = left
</text>

<values>
/ nFollowers = null
</values>

<trial exampleTrial>
/ onTrialBegin = {
    values.nFollowers = round(rand(10000, 50000));
}
/ stimulusFrames = [1=followersText]
/ validResponse = (" ")
</trial>

Would this also work? Why does values need to first be null? Thanks!

<values>
/ nFollowers = round(rand(10000, 50000));
</values>

<text followersText>
/ items = ("<%subString(values.nFollowers, 0, 2)%>,<%subString(values.nFollowers, 2, 3)%> followers")
/ position = (20%, 65%)
/ fontstyle = ("Arial", 2%, false, false, false, false, 5, 0)
/ color = steelblue
/ halign = left
</text>

<surveypage high_social_ID>
/ questions = [1=backgroundImage_ID_1; 2=profileImage; 3=slider_bar_social_1]
/ stimulusframes = [
1=background_outer;
2=background;
3=nameImage;
4=followersText;
5=connectionsText_high;
6=locationText_ID;
7=dot_high]
/ nextlabel = "Next"
/ showpagenumbers = false
/ recorddata = true
/ navigationbuttonfontstyle = ("Arial", 12pt, false)
</surveypage>

<block socialONLY>
/ trials = [
1-8=noreplacenorepeat(
high_social_AR,
high_social_SC,
high_social_TN,
high_social_ID,
low_social_AR,
low_social_SC,
low_social_TN,
low_social_ID)
]
</block>


You can do this, if you don't want the value (a variable) to ever change. Then the round(rand()) expression is evaluated a single time when the script is parsted, and whatever the result is the value the variable will have. Usually, however, you'll want variables to change in specific ways at speciffic times, so you initialize (see below) and set it to whatever you need later.

> Why does values need to first be null?

It doesn't have to. It's a normal way to initialize a variable whose value is to be determined later.

Got it. Thanks! How do I make it so that the value changes with each surveypage?

You set the value to a new one /onTrialBegin in the <surveypage>, just like I showed in the example code I gave you.
wmfang
wmfang
Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)
Group: Forum Members
Posts: 20, Visits: 64
Dave - 9/10/2025
wmfang - 9/10/2025
Dave - 9/10/2025
wmfang - 9/9/2025
I would like to display text that includes a random number between 10000 and 50000, but for the text to include the commas so that it reads as "10,000 followers" and "50,000 followers".

This is what I currently have:

<text followersText>
/ items = ("<% round(rand(10000, 50000)) %> followers")
/ position = (20%, 65%)
/ fontstyle = ("Arial", 2%, false, false, false, false, 5, 0)
/ color = steelblue
/ halign = left
</text>

Thanks!

<text followersText>
/ items = ("<%subString(values.nFollowers, 0, 2)%>,<%subString(values.nFollowers, 2, 3)%> followers")
/ position = (20%, 65%)
/ fontstyle = ("Arial", 2%, false, false, false, false, 5, 0)
/ color = steelblue
/ halign = left
</text>

<values>
/ nFollowers = null
</values>

<trial exampleTrial>
/ onTrialBegin = {
    values.nFollowers = round(rand(10000, 50000));
}
/ stimulusFrames = [1=followersText]
/ validResponse = (" ")
</trial>

Would this also work? Why does values need to first be null? Thanks!

<values>
/ nFollowers = round(rand(10000, 50000));
</values>

<text followersText>
/ items = ("<%subString(values.nFollowers, 0, 2)%>,<%subString(values.nFollowers, 2, 3)%> followers")
/ position = (20%, 65%)
/ fontstyle = ("Arial", 2%, false, false, false, false, 5, 0)
/ color = steelblue
/ halign = left
</text>

<surveypage high_social_ID>
/ questions = [1=backgroundImage_ID_1; 2=profileImage; 3=slider_bar_social_1]
/ stimulusframes = [
1=background_outer;
2=background;
3=nameImage;
4=followersText;
5=connectionsText_high;
6=locationText_ID;
7=dot_high]
/ nextlabel = "Next"
/ showpagenumbers = false
/ recorddata = true
/ navigationbuttonfontstyle = ("Arial", 12pt, false)
</surveypage>

<block socialONLY>
/ trials = [
1-8=noreplacenorepeat(
high_social_AR,
high_social_SC,
high_social_TN,
high_social_ID,
low_social_AR,
low_social_SC,
low_social_TN,
low_social_ID)
]
</block>


You can do this, if you don't want the value (a variable) to ever change. Then the round(rand()) expression is evaluated a single time when the script is parsted, and whatever the result is the value the variable will have. Usually, however, you'll want variables to change in specific ways at speciffic times, so you initialize (see below) and set it to whatever you need later.

> Why does values need to first be null?

It doesn't have to. It's a normal way to initialize a variable whose value is to be determined later.

Got it. Thanks! How do I make it so that the value changes with each surveypage?
Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 109K
wmfang - 9/10/2025
Dave - 9/10/2025
wmfang - 9/9/2025
I would like to display text that includes a random number between 10000 and 50000, but for the text to include the commas so that it reads as "10,000 followers" and "50,000 followers".

This is what I currently have:

<text followersText>
/ items = ("<% round(rand(10000, 50000)) %> followers")
/ position = (20%, 65%)
/ fontstyle = ("Arial", 2%, false, false, false, false, 5, 0)
/ color = steelblue
/ halign = left
</text>

Thanks!

<text followersText>
/ items = ("<%subString(values.nFollowers, 0, 2)%>,<%subString(values.nFollowers, 2, 3)%> followers")
/ position = (20%, 65%)
/ fontstyle = ("Arial", 2%, false, false, false, false, 5, 0)
/ color = steelblue
/ halign = left
</text>

<values>
/ nFollowers = null
</values>

<trial exampleTrial>
/ onTrialBegin = {
    values.nFollowers = round(rand(10000, 50000));
}
/ stimulusFrames = [1=followersText]
/ validResponse = (" ")
</trial>

Would this also work? Why does values need to first be null? Thanks!

<values>
/ nFollowers = round(rand(10000, 50000));
</values>

<text followersText>
/ items = ("<%subString(values.nFollowers, 0, 2)%>,<%subString(values.nFollowers, 2, 3)%> followers")
/ position = (20%, 65%)
/ fontstyle = ("Arial", 2%, false, false, false, false, 5, 0)
/ color = steelblue
/ halign = left
</text>

<surveypage high_social_ID>
/ questions = [1=backgroundImage_ID_1; 2=profileImage; 3=slider_bar_social_1]
/ stimulusframes = [
1=background_outer;
2=background;
3=nameImage;
4=followersText;
5=connectionsText_high;
6=locationText_ID;
7=dot_high]
/ nextlabel = "Next"
/ showpagenumbers = false
/ recorddata = true
/ navigationbuttonfontstyle = ("Arial", 12pt, false)
</surveypage>

<block socialONLY>
/ trials = [
1-8=noreplacenorepeat(
high_social_AR,
high_social_SC,
high_social_TN,
high_social_ID,
low_social_AR,
low_social_SC,
low_social_TN,
low_social_ID)
]
</block>


You can do this, if you don't want the value (a variable) to ever change. Then the round(rand()) expression is evaluated a single time when the script is parsted, and whatever the result is the value the variable will have. Usually, however, you'll want variables to change in specific ways at speciffic times, so you initialize (see below) and set it to whatever you need later.

> Why does values need to first be null?

It doesn't have to. It's a normal way to initialize a variable whose value is to be determined later.
wmfang
wmfang
Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)
Group: Forum Members
Posts: 20, Visits: 64
Dave - 9/10/2025
wmfang - 9/9/2025
I would like to display text that includes a random number between 10000 and 50000, but for the text to include the commas so that it reads as "10,000 followers" and "50,000 followers".

This is what I currently have:

<text followersText>
/ items = ("<% round(rand(10000, 50000)) %> followers")
/ position = (20%, 65%)
/ fontstyle = ("Arial", 2%, false, false, false, false, 5, 0)
/ color = steelblue
/ halign = left
</text>

Thanks!

<text followersText>
/ items = ("<%subString(values.nFollowers, 0, 2)%>,<%subString(values.nFollowers, 2, 3)%> followers")
/ position = (20%, 65%)
/ fontstyle = ("Arial", 2%, false, false, false, false, 5, 0)
/ color = steelblue
/ halign = left
</text>

<values>
/ nFollowers = null
</values>

<trial exampleTrial>
/ onTrialBegin = {
    values.nFollowers = round(rand(10000, 50000));
}
/ stimulusFrames = [1=followersText]
/ validResponse = (" ")
</trial>

Would this also work? Why does values need to first be null? Thanks!

<values>
/ nFollowers = round(rand(10000, 50000));
</values>

<text followersText>
/ items = ("<%subString(values.nFollowers, 0, 2)%>,<%subString(values.nFollowers, 2, 3)%> followers")
/ position = (20%, 65%)
/ fontstyle = ("Arial", 2%, false, false, false, false, 5, 0)
/ color = steelblue
/ halign = left
</text>

<surveypage high_social_ID>
/ questions = [1=backgroundImage_ID_1; 2=profileImage; 3=slider_bar_social_1]
/ stimulusframes = [
1=background_outer;
2=background;
3=nameImage;
4=followersText;
5=connectionsText_high;
6=locationText_ID;
7=dot_high]
/ nextlabel = "Next"
/ showpagenumbers = false
/ recorddata = true
/ navigationbuttonfontstyle = ("Arial", 12pt, false)
</surveypage>

<block socialONLY>
/ trials = [
1-8=noreplacenorepeat(
high_social_AR,
high_social_SC,
high_social_TN,
high_social_ID,
low_social_AR,
low_social_SC,
low_social_TN,
low_social_ID)
]
</block>


Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 109K
wmfang - 9/9/2025
I would like to display text that includes a random number between 10000 and 50000, but for the text to include the commas so that it reads as "10,000 followers" and "50,000 followers".

This is what I currently have:

<text followersText>
/ items = ("<% round(rand(10000, 50000)) %> followers")
/ position = (20%, 65%)
/ fontstyle = ("Arial", 2%, false, false, false, false, 5, 0)
/ color = steelblue
/ halign = left
</text>

Thanks!

<text followersText>
/ items = ("<%subString(values.nFollowers, 0, 2)%>,<%subString(values.nFollowers, 2, 3)%> followers")
/ position = (20%, 65%)
/ fontstyle = ("Arial", 2%, false, false, false, false, 5, 0)
/ color = steelblue
/ halign = left
</text>

<values>
/ nFollowers = null
</values>

<trial exampleTrial>
/ onTrialBegin = {
    values.nFollowers = round(rand(10000, 50000));
}
/ stimulusFrames = [1=followersText]
/ validResponse = (" ")
</trial>

wmfang
wmfang
Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)Associate Member (127 reputation)
Group: Forum Members
Posts: 20, Visits: 64
I would like to display text that includes a random number between 10000 and 50000, but for the text to include the commas so that it reads as "10,000 followers" and "50,000 followers".

This is what I currently have:

<text followersText>
/ items = ("<% round(rand(10000, 50000)) %> followers")
/ position = (20%, 65%)
/ fontstyle = ("Arial", 2%, false, false, false, false, 5, 0)
/ color = steelblue
/ halign = left
</text>

Thanks!
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search