Create "random" function in processing.js?

This function turn back a random number

IntList listRand;
void setup() {
 listRand=new IntList();
// void draw() { }

int randm(int a,int b){
int y;  
int x=int( random(a,b) );
 if (listRand.hasValue(x) == false) 
 {
  listRand.append(x); 
  y=x; 
 }
 else y=randm(a,b);
 return y;
}

But there isn’t the IntList in processing.js
Is there analog/equivalent of hasValue() function for arrays in processing.js?

1 Like

-a- something is wrong with the posted code,
as your question is about
processing.js
why you not show us the problem code MCVE at
https://www.openprocessing.org

-b- but i see
http://processingjs.org/reference/ArrayList/
try if that helps?
( i was looking for arraylist.shuffle() , but also not exists )

-c- is your question about

  • intlist?

or as the title says about

  • function making random?

did you check on
http://processingjs.org/reference/randomSeed_/

1 Like

yes, function making random and new random number != previous random numbers

Oh, ArrayList function contains() is the analog of hasValue() function and it’s works, thanks :slight_smile:

2 Likes