From the course: Processing: Interactive Data Visualization

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Shuffling with Java

Shuffling with Java - Processing Tutorial

From the course: Processing: Interactive Data Visualization

Start my 1-month free trial

Shuffling with Java

The last function I want to show you that deals with randomness in Processing is how to shuffle the items in an array. Now, you would think that this would be an easy thing to do, but unfortunately Processing does not have a built-in shuffle function and I've seen a number of people create rather long Byzantine complicated functions that can do shuffling. On the other hand, there is a shortcut for this and it is because Processing is based on Java and while Processing does not have a built-in shuffle function, Java does and so what I'm going to show is you is how to import a little bit of Java code and run it to shuffle items in an array. Let's start by simply putting little comment up here at the top, with the sketch name and then I'm going to put -- I have to import a library and it's the Java utilities and so I write import and then java.util.* and that brings in all of the files within that particular folder and once I get that in, I can then define my array. Now I'm going to use…

Contents