dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: How can not repeat a random number

  1. #1
    Member
    Join Date
    May 2016
    Posts
    97

    How can not repeat a random number

    hello,

    How can not repeat a random number




    button code:
    PHP Code:
    on (release) {
    var 
    n:int=Math.randomInt(20) ;
    kofa ;    
    MC.loadMovie("pic" add n add ".jpg");
    // here i need code 
    //to disable repeat numbers
    // it means if n = 2 
    // the number 2 dont show again

    Attached Files Attached Files

  2. #2
    Member
    Join Date
    May 2016
    Posts
    97
    hello
    any help , please

  3. #3
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    893
    you put the numbers into array [1,22,3,6,8,2,...] and then pop() them one by one, for example.

    another way would be something like:
    PHP Code:
    var had = {};
    function 
    uniqueRandom(n) {
     var 
    r; do {
      
    Math.randomInt(n);
     } while (
    had[r]);
     
    had[r] = true;
     return 
    r;

    who is this? a word of friendly advice: FFS stop using AS2

  4. #4
    Member
    Join Date
    May 2016
    Posts
    97
    thanks realMakc
    if n=Math.randomInt(800)
    how can i generate the array and generate array items randomly
    can you write the code, please

  5. #5
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    893
    Quote Originally Posted by kofa View Post
    can you write the code, please
    nope. I know, you said 'please', but I still do not feel like. maybe later.
    who is this? a word of friendly advice: FFS stop using AS2

  6. #6
    Member
    Join Date
    May 2016
    Posts
    97
    my final file


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center