Example Code

Randomize an Array Using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

This VI will randomize the order of Input Array elements

 

Description

This VI is effectively the reverse of the Sort 1D Array VI. it will take the Input Array and randomize the order of its elements. First, the VI initializes an empty array and gets the size of the array input. At every iteration, it will generate a random number and multiply by the array's size, representing an index in the array. If this value is not in the array, insert it. The loop is stopped when the placeholder array has the same number of elements as the input array. Finally, the input array is indexed with the Randomized Array. This is only one possible method to randomize an array's elements.

 

Requirements

  • LabVIEW 2012 (or compatible)

Steps to Implement or Execute Code

1. Manually Initialize the Input Array
2. Run the VI

 

Additional Information or References
VI Block Diagram

Randomize Array LV2012 NI Verified BD.jpg

 

 **This document has been updated to meet the current required format for the NI Code Exchange.** 

 

 

 
Product Support Engineer
National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
JLSx
Member
Member
on

That's very nice!  Haven't played yet as the VI is still queing (virus scanning) but I can already see several nice use cases for this when testing and wanting to create data sets etc.

Thanks for posting!

Best,
JLSx
Sixclear
VI High - LabVIEW Programming Video Blog
altenbach
Knight of NI Knight of NI
Knight of NI
on

For a better solution, see my comments at the bottom of the page here.