How to create shuffling effect when mouse pressed and choose one when mouse is released

So I have an array of pictures and another array of names of the pictures. When the mouse is pressed, the names and pictures appear on the screen and shuffles. When the mouse is realeased, it stops at one image and corresponding name. First, I don’t know how to show image and corresponding name when the mosue is released.

boolean shuffle= false;
int num= int(random(0,8));
void draw() {
  //if im cycling through the pictures, it shows this
  if(shuffle){
   fill(0);
  image(img[int(random(0,img.length))], 0, 0);
  rect(width/2, 0, width/2, height);
  fill(255,0,0);
  textFont(f,40);
  text(names[int(random(0,names.length))],800,400);
  }
  else if(!shuffle){
    background(0);
    image(img[num],0,0);
    text(names[num],800,400);
  }
  }