04-26-2014 01:53 PM
hello guys!i'm trying to create a basic dice vi program that generates a random number between 1-6 when triggered,two of the criteria i tried to implement are:
1.no zero
2.the previous value must not be the same as the current one
i tried to solve it using a feed back loop but still the output isn't satisfactory,where am i doing it wrong?thanks in advance 🙂
The block diagram:
Solved! Go to Solution.
04-26-2014 02:21 PM - edited 04-26-2014 02:22 PM
Your code makes little sense. Why is there no outer loop? (are you using continuous run? Don't!)
So you want three different unique integer values between 1..6, right? Why do you think you need so much code, including two feedback nodes and an expanded shift register??? Why do you have all these orange wires if you want integers? Take a step back and try to redesing it from scratch!
Also rouding to nearest is not good, because the edge values will only have half the probability as the other values.
Here's an idea: create an array from 1..6, riffle it, and take the first three elements. 😄 Se how far you get.
04-29-2014 03:49 PM - edited 04-29-2014 03:51 PM
I have a vi that I recently made to generate numbers for a powerball number generator. I have attached it.
A few notes:
1. I used the OpenG vi "remove duplicates from array", so you may need to get the OpenG toolkit for this to work.
2. My vi generates from 1 to 59, not 1-6 (should be an easy change).
If you have any other questions/comments do not hesitate to ask, also if anyone wants a copy of the powerball number generator I would be happy to share.
Best of luck,
Kevin
04-29-2014 06:26 PM - edited 04-29-2014 06:27 PM
@kstrauch wrote:
I have a vi that I recently made to generate numbers for a powerball number generator. I have attached it.
I think the OP allows duplicate numbers, just that consecutive numbers should not be identical. A different problem.
Some comments about your powerball:
Here's what I would do (for the lower part you could also keep your code, but all-blue is nicer. :D)
04-30-2014 03:49 PM
After reading altenbach's comments, I have drafted a quick example of one way to do this. I would appreciate any advice or comments that altenbach or anyone else has on my code, as I am still fairly new to LabVIEW. I believe this meets the criteria that the OP stated.
Regards,
Kevin
04-30-2014 04:22 PM - edited 04-30-2014 04:22 PM
@kstrauch wrote:
After reading altenbach's comments, I have drafted a quick example of one way to do this. I would appreciate any advice or comments that altenbach or anyone else has on my code, as I am still fairly new to LabVIEW. I believe this meets the criteria that the OP stated.
The main problem is that it is not scalable. For example if you later need to modify it for 10 elements, you would need to almost start coding from scratch. Also the algorithm itself does not scale well because you start over with each try. For example if you would need to generate an array of size 1000 with these requirements (no consecutive elements with the same value), you would need to generate a roughly infinite number of arrays before one meets the criterium. This could take forever. 😄
All you need to do is generate a new element until it is different from the previous, and repeat until you have three. Here's one possibility.
05-06-2014 01:58 PM
@altenbach wrote:
@kstrauch wrote:
I have a vi that I recently made to generate numbers for a powerball number generator. I have attached it.
I think the OP allows duplicate numbers, just that consecutive numbers should not be identical. A different problem.
Some comments about your powerball:
- Index array is resizable.
- If you want consecutive elements from index array, you don't need to wire the indices.
- Why are your indicators DBL? They should match the data representation of the wire.
- Seems like way too much code.
Here's what I would do (for the lower part you could also keep your code, but all-blue is nicer. :D)
Whats with that for loop? init the array and add 1 to the index out of riffle
05-06-2014 02:02 PM
@JÞB wrote:
@altenbach wrote:
@kstrauch wrote:
I have a vi that I recently made to generate numbers for a powerball number generator. I have attached it.
I think the OP allows duplicate numbers, just that consecutive numbers should not be identical. A different problem.
Some comments about your powerball:
- Index array is resizable.
- If you want consecutive elements from index array, you don't need to wire the indices.
- Why are your indicators DBL? They should match the data representation of the wire.
- Seems like way too much code.
Here's what I would do (for the lower part you could also keep your code, but all-blue is nicer. :D)
Whats with that for loop? init the array and add 1 to the index out of riffle
Whatever. The constant folding will take care of it anyways.
05-06-2014 02:26 PM
@crossrulz wrote:
Jeff·Þ·Bohrer wrote: Whats with that for loop? init the array and add 1 to the index out of riffleWhatever. The constant folding will take care of it anyways.
Constant folding will NOT take care of it if the addition is after the riffle operation. 😉
05-07-2014 08:27 AM
@altenbach wrote:
@crossrulz wrote:
Jeff·Þ·Bohrer wrote: Whats with that for loop? init the array and add 1 to the index out of riffleWhatever. The constant folding will take care of it anyways.
Constant folding will NOT take care of it if the addition is after the riffle operation. 😉
In either case there is a "constant folded" input into riffle. I'm fairly crtain the only way to fold the output of riffle would be to have a constant seed but, that sort of defeats its purpose