Random event between A & B functions on button release?

  • CE/ Pyrocy
  • Proficient
  • Proficient
  • User avatar
  • Posts: 374
  • Loc: Santa Barbara, CA

Post 3+ Months Ago

How do I use AS2 to make a button event choose either to go to URL #1 or URL #2 randomly choosing either one 50% of the time.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

I think this is a fairly 50% chance :)
Code: [ Select ]
var randNumber = Math.ceil(Math.random()*100);
if (randNumber < 50)
 getURL(url1);
else
getURL(url2);
  1. var randNumber = Math.ceil(Math.random()*100);
  2. if (randNumber < 50)
  3.  getURL(url1);
  4. else
  5. getURL(url2);
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

This works also (put your URL's in an array and randomize the array)

ACTIONSCRIPT Code: [ Select ]
on (release)  {
   
      link_arr = ["www.ozzu.com", "www.google.com"];
        ranNum = Math.floor(Math.random()*link_arr.length);
        getUrl("http://" + link_arr[ranNum]);
}
  1. on (release)  {
  2.    
  3.       link_arr = ["www.ozzu.com", "www.google.com"];
  4.         ranNum = Math.floor(Math.random()*link_arr.length);
  5.         getUrl("http://" + link_arr[ranNum]);
  6. }


I think the inherent nature of random makes that about 50/50 kinda like the toss of a coin with only two URI's. And of course you can add as many URI's as you want to your array.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 12 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.