VynxDev

Shuffle Image Array Help

Jan 25th, 2021
2,053
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Sub shuffleArray(arr As Image())
  2.         Dim n As Integer = arr.Length
  3.         Dim ran As New Random
  4.  
  5.         For i = 0 To arr.Length - 1
  6.             swap(arr, i, i + ran.Next(n - i))
  7.         Next
  8.  
  9.     End Sub
  10.     Public Sub swap(array As Image(), a As Integer, b As Integer)
  11.         Dim temp As Image = array(a)
  12.         array(a) = array(b)
  13.         array(b) = temp
  14.     End Sub
  15.  
  16.     Public Sub loadImages(images As Image())
  17.         shuffleArray(images)
  18.         For Each pb As PictureBox In cb 'Loops through all pictureboxes and fills them with an image.
  19.            pb.BackgroundImage = images(i)
  20.             pb.BackgroundImageLayout = BackgroundImageLayout.Stretch
  21.             i += 1
  22.         Next
  23.  
  24.     End Sub
RAW Paste Data