LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

where am i going wrong?

Solved!
Go to solution

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 🙂

2014-04-27 00_09_04-Untitled 3.jpg            2014-04-27 00_09_17-Untitled 3.jpg

 

 

The block diagram:

2014-04-27 00_20_28-dice.vi Block Diagram.jpg

0 Kudos
Message 1 of 10
(3,043 Views)

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.

0 Kudos
Message 2 of 10
(3,030 Views)

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

0 Kudos
Message 3 of 10
(2,931 Views)

@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)

 

 

 

0 Kudos
Message 4 of 10
(2,897 Views)

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

0 Kudos
Message 5 of 10
(2,854 Views)
Solution
Accepted by topic author krishnac7

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

 

 

 

0 Kudos
Message 6 of 10
(2,840 Views)

@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


"Should be" isn't "Is" -Jay
0 Kudos
Message 7 of 10
(2,681 Views)

@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.Smiley Tongue


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 10
(2,676 Views)

@crossrulz wrote:

Jeff·Þ·Bohrer wrote: 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.Smiley Tongue


Constant folding will NOT take care of it if the addition is after the riffle operation. 😉

0 Kudos
Message 9 of 10
(2,659 Views)

@altenbach wrote:

@crossrulz wrote:

Jeff·Þ·Bohrer wrote: 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.Smiley Tongue


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 purposeSmiley Wink


"Should be" isn't "Is" -Jay
0 Kudos
Message 10 of 10
(2,595 Views)