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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

framed colour box colour changed randomly - using red, blue and yellow

Solved!
Go to solution

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

0 Kudos
Message 1 of 5
(2,574 Views)
Solution
Accepted by topic author Ned_Kelleher

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:

2014-12-10_17-35-24.png


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 2 of 5
(2,567 Views)

Cool

 

Thank you Sam

 

Clicked Kudos and This is the Solution buttons!

 

Thanks again!

0 Kudos
Message 3 of 5
(2,559 Views)
Solution
Accepted by topic author Ned_Kelleher

@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. 😞

Message 4 of 5
(2,537 Views)

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.


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 5 of 5
(2,504 Views)