A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Classic random script

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    3

    Classic random script

    I need a bit of help putting this bit together. the game is 3 prizes 10 cards. I have 10 cards face down and numbered 1 -10 .

    part 1 - I turn a card and one of the prize is randomly selected with a %75 chance on winning and %25 on losing.

    part 2 - If a card is chosen all the remaining cards are turned round with random scatter of the remaining prizes and lose so it seems that there was a lose or prize under the chosen card the whole time.

    I found this but dont know if I can use it for part 1, is it even compatible with AS3 in CS4?. I dont understand =14 =69. Also help with part 2 is needed.

    Code:
    on (release) {
    
    var engine = random(99); var randomnumber;
    
    //This tells us that you have a 15% chance of getting the number 18 if (engine>=0 && engine<=14) { randomnumber = 18; } else if (engine>=15 && engine<=69)
    
    { //This tells us we have a 55% chance of having the number 12 randomnumber = 12; } else { //this is the remainding percentage which is accorded to "9". randomnumber = 9; }

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    106
    the code above is actionscript 2 (AS2)... this will not work with AS3... but you could probably modify it.

    If I were to solve this problem... I would start with an array that holds all 10 items... 7 items would be winners and 3 would be losers. then you could shuffle the array and then populate all the cards. This way you the person would automatically have 70% chance of winning and you wouldn't need any extra logic to help you solve your problem.

    to answer your question about =14 and =69, the person is generating a random number between 1-99.
    First "if" statement says if the random number is between 0 and 14, then it sets the number to 18
    Second "else if" statement says if the random number is between 15 and 69, then it sets the number to 12
    Last "else" statement says if the random number is any other number (higher than 70) it sets the number to 9

    That code is not doing what I believe you are wanting.

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