Loading a Random File

edited October 2013 in Questions about Code

hi,

i want to load a random file into my HShape Class.. I got 10 Vector files named vector1.svg to vector10.svg

now is it possible to load one random each time? d = new HShape("vectors1.svg");

perhaps someting like this:

d = new HShape(""vectors""random(1,10)"".svg"");

Answers

  • Answer ✓
    String name = "vectors" + (int)random(1, 11) + ".svg";
    d = new HShape(name);
    

    that said, don't do this in your draw loop as it'll slow it down. better to load all the files into an array during setup() and then choose a random one from that array when you need one.

  • thanks very much!!!

Sign In or Register to comment.