From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
12-10-2014 11:10 AM
Hello
I want the user to do something when the colour box changes from black (ready) to green (set), and then Red, Yellow or Blue (go). The user wil know what colours are coming at them.
The user will will push a specific sequence of buttons according to colour.
Success will be pushing the sequence of buttons assigned to a specific colour. There are 16 push buttons. (this is for recall and reaction time)
Anyway, I can write the program no problem.
The user might do one trial of red (and push a specific sequence of buttons according to red), then blue, then yellow. I may get them to repeat a colour so they will do four trials.
Sorry for being long winded.
My question is how would I randomly generate a color to begin a trial.
So this set of trials is not known by the subject because on go the colour has been randomly presented as prompt.
Any help would be greatly appreciated!
Thanking you all in advance,
NK
Solved! Go to Solution.
12-10-2014 11:35 AM
If you have a fixed set of colours, put them in an array and generate a random number between 0 to (Array Size-1) and index an item out of the array. Multiply the Random number (0-1), multiply by the maximum value and round to nearest to get your index.
If you want to generate a truly random colour, use the RGB to Colour VI and wire 3 random numbers between 0-255 to generate a random Red, Green and Blue component like this:
12-10-2014 11:48 AM
Cool
Thank you Sam
Clicked Kudos and This is the Solution buttons!
Thanks again!
12-10-2014 01:32 PM
@Sam_Sharp wrote:
If you have a fixed set of colours, put them in an array and generate a random number between 0 to (Array Size-1) and index an item out of the array. Multiply the Random number (0-1), multiply by the maximum value and round to nearest to get your index.
This is a statistically flawed procedure, because the values zero and 255 only occur with half the probability of all other values. You should multiply with 256 and then round to -infinity instead. This will give you equal probability for all values (0..255).
Yes, it is probably not that important in this particular application. Still, in the near or far future somebody sees this posts and then tries to make a six sided dice simulation with the given algorithm. It would be highly flawed. 😞
12-11-2014 03:48 AM - edited 12-11-2014 03:52 AM
Thanks for the tip (my stats is a little rusty!), I was about to ask what happens when you roll a 1 then you end up with 256 but read the documentation and found that it generates a number >= 0 and < 1.