Jump to content
  • 0

Random number not repeat


char0

Question


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  13
  • Reputation:   0
  • Joined:  12/20/11
  • Last Seen:  

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
Link to comment
Share on other sites

3 answers to this question

Recommended Posts


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10013
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

you can try this

http://upaste.me/r/7c658f

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

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
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  13
  • Reputation:   0
  • Joined:  12/20/11
  • Last Seen:  

Thank Capuche and Emistry. The Emistry code worked fine, but  both were very helpful. :)

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.

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.

×
×
  • Create New...