A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Randomizing an array's trace statements by percentage

  1. #1
    Member
    Join Date
    Oct 2006
    Posts
    48

    Randomizing an array's trace statements by percentage

    Hello

    I have an array that I want to shuffle but at different percentages. Like "Hello" would show up 80% in the Output window. "Bye" would show the other 20% of the time.

    How do I do this?

    Code:
    var myArray:Array = new Array("Hello", "Bye");
    
    function randomIt()
    {
    	randomizeArray = random(myArray.length);
    	trace(myArray[randomizeArray]);
    }
    
    setInterval(randomIt,1000);

  2. #2
    Member
    Join Date
    Oct 2006
    Posts
    48
    I think I found a way. Is this the proper way to do it?

    Code:
    var myArray:Array = new Array("Hello", "Bye");
    var chance = random(99);
    
    function randomIt()
    {
    
    	if (chance >= 0 && chance <= 89)
    	{
    		trace(myArray[0]);
    	}
    	else
    	{
    		trace(myArray[1]);
    	}
    }
    
    setInterval(randomIt,1000);

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