From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Re: Random number generation, odd and even determination etc.

How to generate a random number from 1 to 50 in array

0 Kudos
Message 1 of 9
(2,926 Views)

Hi raki,

 

no need to hijack old threads for your own question!

 

If you would search this forum you would find a lot of possible solutions as your question comes up quite often! (It's a typical task to let beginners learn LabVIEW features.)

 

generate a random number

There is a LabVIEW function giving you random numbers with 0 < x < 1 (according to LV2011 help).

 

from 1 to 50

You need some simple math to scale the number you already got…

 

in array

Usually you use loops to generate arrays…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 9
(2,915 Views)

@raki7 wrote:

How to generate a random number from 1 to 50 in array


Please show the entire homework assignment. A lot of information seems missing.

 

  • Do you want only integers or real random floating point numbers?
  • In the subject, you talk about odd/even, but you don't mention it in the post.*
  • What does the "etc." in the subject stand for.*
  • To generate a random number, you don't need an array.
  • How many random numbers do you need to generate?

Have you done a forum search? Plenty of solutions have been posted in the past.

 

* EDIT: I guess you did not write the subject line and it has little to do with your posts. It came from the thread you hijacked before the post got moved.

Message 3 of 9
(2,908 Views)

Hi GerdW

im using a random number function to generate numbers from 0 to 50, but im getting the repeated numbers in a array and as i run it multiple times, numbers gets changed. i wanna know how to remove the repeated numbers in the array. plz can you help me out with this..

0 Kudos
Message 4 of 9
(2,802 Views)

Hi raki,

 

when there is a problem in YOUR VI you need to debug YOUR VI.

Or you attach YOUR VI so we can also debug it…

 

(I prefer LV2014.)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 9
(2,796 Views)

Im using LV2016....

Download All
0 Kudos
Message 6 of 9
(2,783 Views)

The simple solution is to create an array of 51 elements (data type does not matter so use a U8 for the smallest memory hit, also use Initialize Array) and then use Riffle.vi.  Use the index array output.  You will now have a random order of numbers from 0 to 50 with no duplicates.  You can use Array Subset if you just need a certain number of values.


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 7 of 9
(2,777 Views)

sorry... im new to labview can you please help me how to design it

0 Kudos
Message 8 of 9
(2,762 Views)

@raki7 wrote:

sorry... im new to labview can you please help me how to design it


I gave you step-by-step instructions for 2 functions that you need.  If you are unwilling to give it a try, I cannot help you.  Or if you are just lost, go through some of the tutorials.

3 Hour Introduction
6 Hour Introduction
LabVEW Basics
Self Paced training for students
Self Paced training beginner to advanced, SSP Required
LabVIEW Wiki on Training
Learning NI
Getting Started with NI Products


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
Message 9 of 9
(2,758 Views)