Jump to content
  • 0

Random number not repeat


Question

Posted (edited)
Hello, I'm trying to generate random numbers not repeated for an array ".p" using the same size an array ".s$".
 
But the NPC is accusing infinite loop. How could I generate numbers not repeated 0-19 without error?

 

 

Grateful for help, Char0.

Edited by char0

3 answers to this question

Recommended Posts

Posted

I don't understand what you wanted to do but about

How could I generate numbers not repeated 0-19 without error?

    setarray .@tmp, 0,1,2,3,4,5;
    .@size = 6;
    while( .@size ) {
        .@r = rand( .@size );// pick a number between 0-19
        set .p[.@i], .@tmp[.@r];
        deletearray .@tmp[.@r],1;
        .@size--;
        .@i++;
    }
  • Upvote 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...