LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Random number generation

I have a matrix  M of size 5 by 8 and all the elements of this matrix are either one or zero.

I want to generate a pair of random number, one for row index (between {0,5} ) and other for column index (between {0,8} ) such that the pair generated

doesn't map to the elements zero of matrix M. The pair should only map to unit elements of M.

How to do this in labview.

 

Thanks 

0 Kudos
Message 1 of 12
(5,374 Views)

Use the random number function to generate the row number, and another to generate the column number (multiply by 6 or 9 respectively, and round down to the nearest integer, the floor function.)

 

Determine if the resulting row and column gives you a zero.  If it does, repeat until it gives you a one.

0 Kudos
Message 2 of 12
(5,367 Views)

Thanks for your reply.

That is fine. But if the number of zeros in the matrix is very less, then the program takes very long time to generate appropriate random numbers.

Is there any solution to this problem ?

0 Kudos
Message 3 of 12
(5,352 Views)

If your matrix is only 6 x 9, that's only 54 possible combinations.  A loop will run so quickly, it's going to hit a 1 before you know it.

 

What are you really trying to do?  The question you posed is very odd.  It sounds more like a homework assignment rather than a real problem.

0 Kudos
Message 4 of 12
(5,343 Views)

Actually the matrix is of bigger size (about 24 by 36) and the number of unit elements in it is vey few (say 25).

And I have to generate an appropriate pair of random number in real time.

0 Kudos
Message 5 of 12
(5,331 Views)

Then why'd you say 6 x 9?  24 x 36 is still not very big.  Why don't you try programming it with the instructions I said and see how it turns out.

 

What do you mean by "real time"?  In computers, real time means something very specific.  A real time operating system means it is running deterministically and the CPU cycles are guaranteed to run in an alotted time.  This can't happen on Windows, Apple, or Linus OS's where the OS can steal CPU cycles to take care of other tasks.

0 Kudos
Message 6 of 12
(5,319 Views)

Thanks for your reply.

 

My experiment is a feedback system. I acquire data from a PXI-5124 digitizer and perform some calculation and then send the feedback signal to a second monitor. Finding a pair of random number appropriately is a part of calculation, so I need to do it quickly.

0 Kudos
Message 7 of 12
(5,294 Views)

How often does the matrix change?

0 Kudos
Message 8 of 12
(5,287 Views)

The matrix does't change in one experimental session. It is specific for every experiment.

0 Kudos
Message 9 of 12
(5,283 Views)

How quickly is "quickly"?  Would milliseconds be fast enough?

 

Have you tried coding yet to see how quick it can be?  This is a simple enough problem.  You could have coded it and tested in the time it has taken you to keep reposting!

 

If the matrix doesn't change during the experiment, then you could go through the array at the initialization process and determine which elements have a 1, how many there are, and then sort out the coordinates for each of those 1'.  (You are still talking only milliseconds.)  Then during the test, do a random number generation to pick out a set of coordinates from your list.  (Which is as quick as you can possibly determine a random number.  One shot!)

0 Kudos
Message 10 of 12
(5,279 Views)