LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

4 random numbers that occur once

Hello
 
I have a problem.
For school a need to make the game Mastermind in Labview.
 
The problem is that i need to have 4 random integer numbers between 0 and 5, placed in an array.
Well that is not so difficult, but the number may not be the same.
Can anyone help me?
 
 
 
0 Kudos
Message 1 of 5
(3,302 Views)

hi there

well:

1. create an array R = {0,1,2,3,4,5} (all valid numbers). use a for loop with autoindexing to do this
2. create a random number i_1 between 0 and 5
3. extract R[i_1]. that's your first random number
4. replace R[i_1] with R[5]
5. create a random number i_2 between 0 and 4
6. extract R[i_2]. that's your second random number
...

repeat the whole thing until R is empty 

Have fun!

Best regards
chris

CL(A)Dly bending G-Force with LabVIEW

famous last words: "oh my god, it is full of stars!"
0 Kudos
Message 2 of 5
(3,291 Views)
You might also use the Unique Numbers and Multiplicity VI to determine if there are duplicates on the back end.  If so force a reroll of all numbers.
See attached example...
 
 
0 Kudos
Message 3 of 5
(3,282 Views)
also pay attention to the random number seed.  It is typically time based.  Therefore, if you run your loop too quickly, it will duplicate the numbers.  I seem to recall seeing a method to change the seed.  What you could do is create your own formula which uses time and the loop number (# of iteration) as a seed for the random number.. This would require some additional steps, but would ensure uniqueness of each number.
 
Did you do a search on random numbers? There was a similar discussion earlier this year on the topic.  I will look for the thread.
 
JLV
Message 4 of 5
(3,272 Views)

Hi Thomy,

Actually, the thread I was referring to is for CVI.  However, I am posting it for your reading pleasure 😉

Enjoy:

http://forums.ni.com/ni/board/message?board.id=180&message.id=14470&query.id=0#M14470

JLV

😄

Message 5 of 5
(3,269 Views)