03-23-2017 08:07 AM
Hi everyone,
I'm trying to make a VI that generates a random number (from 0 to 10 per example), but never generates a same number and stops when all the numbers have been generated. I don't know if this is clear enough.
Solved! Go to Solution.
03-23-2017 08:14 AM
Are you asking a question about your code?
Is this a homework assignment?
The use of 1 divided by (there is a 1/x reciprocal function on the palette, by the way) and the quotient remainder is a very odd way to generate a random number. Usually you just multiply the random number by the number of different values you want, then round down. So to get 0 to 10, multiply by 11 and round down.
I don't see any loop in your VI, so this is only going to execute once.
03-23-2017 08:21 AM - edited 03-23-2017 08:22 AM
Something like this:
Note that, very unlikely, it is possible that you end up with one 11 in the dataset.....
EDIT: Additionally, the other case(s) of the case structure are homework 🙂
03-23-2017 08:43 AM
@Norbert_B wrote:
Note that, very unlikely, it is possible that you end up with one 11 in the dataset.....
EDIT: Additionally, the other case(s) of the case structure are homework 🙂
Actually, I don't think you can get an 11. You'd have to get a 1 out of the random number, but it is defined as 0 to 0.99999........ It includes 0 on the lower end, but does not include 1 on the upper end.
(Read the context help. )
03-23-2017 09:02 AM
@RavensFan wrote:
[...]You'd have to get a 1 out of the random number, but it is defined as 0 to 0.99999........ It includes 0 on the lower end, but does not include 1 on the upper end.
(Read the context help. )
That is right. However, i think that in older versions of LV the help was not that accurate (as i doubt that RandomNumber has been changed function wise).
Well, anyhow, that makes my code work 100%, so it is good news for me 🙂
03-23-2017 09:38 AM
One simple solution would be to use the Ramp function to create an array of numbers from 0 to 10 and then the Riffle function. The Riffle just randomizes the order in the array. There is also an example floating around where you could just use the Initialize Array to create an array with 11 elements (value does not matter here) and use the Index output of the Riffle as your random numbers.
03-23-2017 09:49 AM
@crossrulz wrote:
One simple solution would be to use the Ramp function to create an array of numbers from 0 to 10 and then the Riffle function.
Assuming this actually is a homework problem... that would be a very interesting solution. If someone handed that to me I don't know if I'd be mad because they obviously didn't do the assignment as I intended, or impressed that they came up with the workaround
03-23-2017 02:49 PM
Without a while loop:
03-24-2017 04:17 AM
Can you please send me the VI?
03-24-2017 04:27 AM
Quick tip: if you can see a dashed border around a LabVIEW screenshot (like paul_cardinale's one above), it is a 'code snippet' and you can drag and drop the code directly onto a block diagram. See here for more info.