Creating a random number - possible?

Hi all

I created a flash ad, which allows you to select 3 different ads, in order, always starting at 1.

I am trying to find the script to generate a random number between 1 and 3. Then, based on this number, he started playing at a predetermined. For example:

If RND # = 1 start playing the framework 7

If RND # = 2 start playing the chord 650

If RND # = 3 start playing the chord 1250

Is this possible? Does anyone have a code for this?

Thank you!

You can use the Math.Random () method to generate a value between 0 and 0.999999. and mutliply that by the number of values you want to allow for (3) in your case.   You can then round off this random number using the Math.Floor method to get an integer value.  So in this case you could end up with 0,1,2.  Which is probably good enough for your intentions, if you could add 1 to it if you really wanted 1,2,3.

var randomNumber:uint = Math.floor (Math.random () * 3);

You could then have an array with three values filling and the NombrAl allows you to specify which is used in a gotoAndPlay() command...

var startFrames:Array = new Array (7, 650, 1250);

gotoAndPlay (startFrames [randomNumber]);

Tags: Adobe Animate

Similar Questions

  • How can I create a random number generator, protected by password and username?

    I have attached a VI that is a random number generator. I want to just be prompted for the name of user and password when I start this generator. There should be three names of users and passwords found in three different files. I would like to know how to link the code username/password for the code generator and how do the program to know that there are three txt files in my computer with usernames and passowrds.


  • Assigning images to the grid according to their value random number cells?

    Hi all!

    I need a good point (or push) in a good way.

    Background

    (With previous assistance from this forum), I created a random number of 12 x 9 grid that scrolls the numbers 1 to 9, a total of twelve times each. Then I created a button that mixes the current grid cells whenever it locks. I now want to use 9 images that I imported as individual symbols in the library (I gave them each their own class called "skin1," 'skin 2',...) "skin9") as the cell labels or equivalent. I also created images as individual video clips (using the.) The class Sprite as extended but base class keeping the real image of class names in line with the name of the object, i.e. the "skin1" image is the class "skin1.as").

    Question

    How can I assign these images for the cells in the grid according to their respective values (from 1 to 9) and ask them to fill the grid, whenever I click on the button 'shuffle'? Thus, for example, in my grid numbers 1 to 9 randomly appear 12 times each. Whenever the number 4 appears in a cell, I want it to be assigned to the picture "4 GB" (which is just a chart that looks like a button and has a fancy number '4' printed top). Here's a piece of code that I use to draw the grid cells with:

    // Creates a grid cell when called by generateGrid().
    private funciton drawCell(_numeral:int):Sprite
    {
         /*
              This is the code I am currently implementing to populate the grids with (although I
              don't want to use text labels as I want to fill each grid with an image according 
              to its numerical value (1 to 9).
         */
         var _label:TextField = new TextField();
         _label.multiline = _label.wordWrap = false;
         _label.autoSize = "center";
         _label.text = String(_numeral);
         // Add numerical label to cell array.
         cellLabels.push(_label);
         var _s:Sprite = new Sprite();
         _s.graphics.lineStyle(2, 0x019000);
         _s.graphics.drawRect(30, 0, cellW, CellH);
         _s.addChild(_label);
         return _s;
    }
    


    While what follows is not the labour code, it will show if all goes well I want to reach inside this function so I can't use the code snippet above to the text labels:

    This will create "if all goes well" a table of 9 images by calling their classes.      var _imageArray:Array = [skin1, skin2, skin3, 4 GB, skin5, skin6, skin7, skin8, skin9];      That's what I want to get for each cell using the matrix in the image above: for (i = 0; I < cells; i ++) {if (_numeral == 1) {/ / Insert image skin1 for each instance of #1 in the grid.}}           } If (_numeral == 2) {/ / Insert image skin 2 for each instance of #2 in the grid.}           }... If (_numeral == 9) {/ / Insert image skin9 for each instance of #9 in the grid.}           }      }

    Again, I want not to use text labels. I have a skin graph custom that I want to go over each number on the grid, based on its value (from 1 to 9). Help with this is greatly appreciated!

    :

    // Creates a grid cell when called by generateGrid().
    private funciton drawCell(_numeral:int):Sprite
    {
         /*
              This is the code I am currently implementing to populate the grids with (although I
              don't want to use text labels as I want to fill each grid with an image according
              to its numerical value (1 to 9).
         */
         var _label:TextField = new TextField();
         _label.multiline = _label.wordWrap = false;
         _label.autoSize = "center";
         _label.text = String(_numeral);
         // Add numerical label to cell array.
         cellLabels.push(_label);
         var _s:Sprite = new Sprite();
         _s.graphics.lineStyle(2, 0x019000);
         _s.graphics.drawRect(30, 0, cellW, CellH);
         _s.addChild(_label);
    
    var classRef:Class=Class(getDefinitionByName("skin"+numeral));var image:*=new classRef();_s.addChild(image);      return _s;
    }
    
    
  • What is the possibility of obtaining the same repeated random number?

    I would like to generate a random number of 5 digits;

    Select round (dbms_random.value (10, 999990)) twice;

    The query above seems pretty good, but what is the possibility of obtaining the same repeated random number? I'm fine with repetition until it spreads not less than a second. Is there such a guarantee?

    Thank you
    VINET

    983902 wrote:
    I would like to generate a random number of 5 digits;

    Select round (dbms_random.value (10, 999990)) twice;

    On my laptop, I can call trunc (dbms_random.value (0,100000))-which allows a random number to range form 0 to 99 000 - 100 000 times per second. The probability of repetition in a second depends on the number of calls per second, but in my case that the worst cases are a value that appeared 8 times and 18 445 values appeared twice.

    From what you have said so far, I'd probably use a column of date and a sequence in a column number (10) - possibly with a separate strain by table - for a high volume system.

    Concerning
    Jonathan Lewis

  • Unique random number

    Hello

    Oracle 11.2.0.1

    Windows

    I have a table something like this:

    create table (ID, number of rnd) rnd;

    I need a process something like this:

    exec genrnd (200,300);

    After executing the procedure, there will be 100 lines in the table of rnd and there will be unique random numbers in the column of rnd.  OK, suppose if I run once again something like this:

    exec genrnd (173,514);

    therefore table will be truncated and (514-173) + 1 = 342 lines will be rnd table and new unique random numbers will be in the column of rnd.

    Column ID is just at the end of the order of.  There will be 1,2,3... 100 or 1,2,3,4... numbers 342.

    I get random number in this way:

    Select trunc (dbms_random.value (200,300)) rnd twice;

    Select trunc (dbms_random.value (173,514)) rnd twice;

    but number must be unique within the given range, so I don't get how this is possible, please help me.

    Thank you.

    Insert into rnd

    Select rownum, one of

    (

    Select * from

    (

    Select rownum + start_value - 1A

    Double connect rownum<= end_value="" -="" start_value="" +="">

    )

    order of dbms_random.value

    );

    This query has 4 parts

    (1) generation X Y numbers in order

    (2) randomized data generated

    (3) assign a rownum for each row of data

    (4) Insert the result in the table

    So he adapts to the requirements of the opus and don't know how

    > Order by on the insert does nothing

    available in photo with this code.

  • How to generate a single random number in a MySQL database

    I create a volunteer and also a separate request form from the seller for an air show. The volunteer and seller info is stored in separate tables in MySQL db, a line by volunteer or the seller. There will be about 100 volunteers and 50 sellers. When the request should immediately be printed by the applicant signed and mailed in. This year we had problems with some people who do not immediately print asked, so I would still give them the possibility to print immediately, but also to send them an email with a link to their specific line in the MySQL database. I have an AutoIncrement primary key for each table field, but I think to send this key to the applicant in an email would be too easy for them to guess a different id and access the information of others.

    I think I should add a column for each table containing a unique random number and then I would send this key in the e-mail to the applicant. So, can anyone suggest a simple way to do this or suggest a better way to give the applicant a way to access their own request and nobody elses not after submitting their form?

    Thank you all.

    Tony Babb

    In your code, you should:

     VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, $s)",
    

    Change the $s to %s and that should solve the problem for you.

    Let me know.  Thank you!

    Chad

  • How can I generate a single random number on a button for use in a VI?

    I'm creating a new VI and need a new random number every time that I hit a button... it will eventually be replaced by externally triggered en boolean, but for now, I would like to just press a button, get a new number, use this number, click the button, get a new number (previous deletion), etc etc.

    Thank you

    -Steve

    Just to add to what SAM has shown you can generate in a different ranges without limit it... It's just a very simple logic... Try this...

  • How to generate a random number within a specified tolerance and control than tolerance.

    I am trying to simulate data without using a data acquisition device using a random number generator and I want to be able to control the "range" the random number generated well.  On the front panel, the user can enter a nominal number, and the random number generator would generate numbers more or less disponibles.003 this number nominal.  The data would be delayed on a chart.  Someone knows how to do this?  Or if it is still possible?

    Just for the sake of information, the random number is supposed to resemble thickness measures, that's why I want to simulate more and less disponibles.003 because the data might be thinner or thicker than the nominal value.

    Thanks in advance!

    Two ways of approaching the issue.  First of all, for even distribution, you can 'Roll the dice', which is the (0,1) random number function, multiply the result by 0.06 and then add Mean - 0.03 to center around average distribution.  If you simulate a real process, my initial guess would be that the results would follow a normal distribution.  In this case, you can use the VI of white noise Gaussian of the palette of generation of signals with a standard deviation of 0.015 if you wanted 0.03 to be the point of 2 sigma, then add average results.

  • Random number by computer

    Hello

    I have a comp with a random number is generated,.

    That's what I have on the keyframe of the rotation:

    seedRandom (index, true);

    myValue = random (50);

    time * myValue ;

    When I duplicate this model, all produce the same results.

    Is it possible for each model generate its own random number?

    Thank you

    Lol the essential point is that a single model makes only once, so it cannot present a different picture depending on where you use it.

    Dan

  • generate a random number between 1 and 10

    Dear All;

    I have an insert... Select and in one of the columns, I would like to generate a random number from 1 to 10, how is this possible. Thank you.

    Select round (dbms_random.value (1,10)) double;

    http://download.Oracle.com/docs/CD/B28359_01/AppDev.111/b28419/d_random.htm#CDEJAHCB

  • zero pad random number

    I am zero button a random number. Can someone explain why it does not work

    TO_CHAR ((TRUNC (DBMS_RAMDOM. (VALUES (1,500)), "0000000000")

    840386 wrote:
    I am zero button a random number. Can someone explain why it does not work

    TO_CHAR ((TRUNC (DBMS_RAMDOM. (VALUES (1,500)), "0000000000")

    You probably want to use LPAD (or possibly RPAD... not sure where you're trying to pad the 0 is here) and not the approach that you have posted.

    A simple google search will give you an idea of how it works and how to use it.

  • Need help random number, if-then AS3

    I found the online AS3 code to generate a random number between 0 and 1.  It looks like this:

    function randomNumber1(low:Number=0,_high:Number=1):Number

    {

    return Math.floor (Math.random () * (1 + high-low)) + low;

    }

    Then I made two buttons given blue1_btn and green1_btn instance names.  I tried to create a random guess the test button to go to another scene.  Here's the code I used for each with different button

    green1_btn.addEventListener (MouseEvent.CLICK, green1);

    function green1(event:MouseEvent):void {}

    if(randomNumber1 == 1)

    {

    gotoAndPlay("Win",1);

    }

    on the other

    {

    gotoAndPlay("Lose",1);

    }

    }

    The other subsitutes touches the word 'blue' where you see 'green' in the code above.

    When I have the test file, I get these errors:

    "* Error * Scene 1, layer green btn code ', frame 2, line 3:1176: comparison between a value with static type of function and may be unrelated to int type.

    if(randomNumber1 == 1)

    "* Error * Scene 1, layer green btn code ', frame 2, line 5:1180: call to a method may be undefined gotoandplay.

    gotoAndPlay("Win",1);

    "* Error * Scene 1, layer green btn code ', frame 2, line 9:1180: call to a method may be undefined gotoandplay.

    gotoAndPlay("Lose",1);

    * Error * scene 1, Layer 'code Blue btn', frame 2, line 3:1176: comparison between a value with static type of function and may be unrelated to int type.

    if(randomNumber1 == 1)

    * Error * scene 1, Layer 'code Blue btn', frame 2, line 5:1180: call to a method may be undefined gotoandplay.

    gotoAndPlay("Win",1);

    * Error * scene 1, Layer 'code Blue btn', frame 2, line 9:1180: call to a method may be undefined gotoandplay.

    gotoAndPlay("Lose",1);

    "* Error * Scene 1, layer green btn code ', frame 2, line 1:1120: access of undefined property green1_btn.

    green1_btn.addEventListener (MouseEvent.CLICK, green1);

    Total ActionScript errors: 7, reported errors: 7

    Read errors after seeing corrections below so that you gain a better understanding.  In addition, the arguments of gotoAndPlay are back in your code...

    function randomNumber1(low:Number=0,_high:Number=1):Number
    {
    return Math.floor (Math.random () * (1 + high-low)) + low;
    }

    green1_btn.addEventListener (MouseEvent.CLICK, green1);

    function green1(event:MouseEvent):void {}
    If (randomNumber1 () == 1)
    {
    gotoAndPlay (1, 'victory');
    }
    on the other
    {
    gotoAndPlay (1, 'lose');
    }
    }

  • generate a random number in a range of duplication no

    Good day people,

    I need help once again. I want to animate an image inside a movieclip with frame label animate1, animate2, animate3 and animate4.

    I managed to generate random numbers, but my concern is I want my animation not animate same image twice, here is my code.

    = main time line code =.

    function randRange(min:Number,_max:Number):Number {}
    Generate a number between and including min - max
    var randomNum:Number = Math.floor (Math.random () *(max-min)) + min;
    Return randomNum;
    }


    build table to hold the frame label names
    var frameArray:Array = new Array();
    frameArray [0] = "animate1";
    frameArray [1] = "animate2";
    frameArray [2] = "animate3";
    frameArray [3] = "animate4";

    Get created random number
    var n: Number = plageAleatoire (0, frameArray.length);


    trace ("n": + n);


    Stop Frame label name
    This.img_ani.gotoAndStop (frameArray [n]);


    trace ("frameArray:" + frameArray [n])

    = label code and frame inside a clip with 4 frames containing different pictures =.

    as layer: stop();

    image tag: animate1, animate2, animate3, animate4

    Any help is greatly appreciated. Thanks in advance.

    It is not a routine of brewing, integrated, but there is a pretty standard shuffle function that was happening around...

    var frameArray:Array = new Array();
    frameArray [0] = "animate1";
    frameArray [1] = "animate2";
    frameArray [2] = "animate3";
    frameArray [3] = "animate4";

    function shuffle (a) {}
    var p;
    var t;
    Ivar var;
    for (ivar =. Length-1; Ivar > = 0; Ivar-) {}
    p = Math.Floor ((Ivar+1) * Math.Random ());
    t = a [ivar];
    a [ivar] = a [p];
    a [p] = t;
    }
    }

    trace (frameArray);  See the property before shuffle

    Use:
    Shuffle (frameArray);

    trace (frameArray);  Show after shuffle

  • Virus on iPhone to clicking on a link. Compound random number several times. What should I do?

    I clicked on a link on Twitter, and then on this site, he asked to check my browser compatibility. When I click on this box he started numbering to a random number and several times. I got calls as fast I have could and also turned my phone works, but I'm afraid that my information may be compromised. What should I do? Thanks to help from there.

    Nothing to do.

    Do not click on those in the future.

    You can't catch a virus like this.

  • How to build a VI that generates a random number between 1 and 80... Help!

    Generate a VI that generates a random number between 1 and 80

    Divide the random number by a number specified in the front panel.

    If the number of seizures is zero, the VI program should light a LED in the face to indicate a divide by zero error.

    Hai edwardty2009,

    Welcome to the forum.

    Thanks for the congratulations.

    Your problem is solved? If so can you please mark as solution what post help better to solve your problem.

    Thank you

    Mathan

Maybe you are looking for

  • Firefox will not run adaware

    I like firefox the best browser ever! but I run adaware security free of charge and it won't download definition files or scan for the follow-up of all the cookies I get is a white screen

  • Noelle Marie

    ROBEL

  • Simple pass works only on Windows 7 pro standard user

    I looked through countless questions simple pass and found no clue. I'm used to simple passage, recognizing the need for a u/p that it registers the new website or offers for me to slide my finger for an existing installation.  This is nothing.  It i

  • Updates for windows vista - code error 646

    I had 8 update to install, and only 4 have been downloaded. 4 other updates are kb973593, kb973704, kb975960 and kb974561, I get the error message 646 have tried repeatedly, but they will not download. Any suggestions?

  • Exception of null on the list pointer implementing values when there are n rows in the table

    Hi Experts,I use JDev 11.1.1.7.I have a VO that I defined a LOV with no search box. In my page, I've added it as af:inputListOfValues, but when there is no rows in the table that I will meet with NPES< AdfcExceptionHandler > < handleException > ADFc: