Jump to content
itchboy

Random Integer Without Repetition

Recommended Posts

Title says what I need help with. I want to create a random integer within a loop that does not repeat. So that means within a range of 4 for example, I would recieve only 0, 1, 2 or 3 in any order, but not two instances of the same number. The desired output would be this:

3,1,2,0

The number must not repeat at the next iteration of the loop either.

 

I have tried using Math::rand%3 and adding a temp variable that checks the previous value of the random integer (during the previous loop interation) but it appears that the value of the temp value becomes garbage once the loop restarts itself.

Can anyone help? Thanks!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...