Math.Random drop a decimal

Hello fellow people,

you have this problem

This.INPUT1.Text = Math.round ((0,140 + Math.Random () * 0,040) * 1000) / 1000;

Sometimes, it gives a response from 0.14 or 0.15, etc, etc...

is there anyway to make it not drop at the end 0, that is to say it should be 0.140 or 0.150 (got a very specific chemistry customer)

Thanks in advance

Alternatively you can use just like this

Tags: Adobe Animate

Similar Questions

  • Math.Random () does not work in BB

    Salvation;

    I just want to ask if the BB API, can give the possibility to generate a number of random if yes how can I do; generally in java J2SE: I CAN DO THIS:

    choice = (int) (Math.Random () * 3 + 1);

    "to generate a random number ' 3 nomber.

    I try to do whit BB I import java.lang.Math;

    and when I try to put Math.Random (), it does not work

    can anyone give me the solution?

    in fact I want to have a HEX number, I think I have the Random one after I'll transforms in HEXA.

    Thank you very much

    Here is exactly what you need to get a random number

    first import

    import java.util.Random
    

    then

    //Random number generator
        Random dice = new Random();
        int num = 0;
        for (int counter=1; counter<=1000; counter++){
            num = dice.nextInt(1000); //it will generate numbers up to 1000
        }
    

    You are welcome!

  • Math.Round () and Math.Random)

    Hello

    Do we have the equivalent methods in J2ME for Math.round () and Math.Random ()? I could not find in Java.util.Math or net.rim.device.api.Math

    Thank you.

    Reshma

    @ JavaMEUser, you can write your own class of math for your application, use the following code...

    public static int round(float f)  {     return (int)(f + 0.5F);   }public static long round(double d) {                return (long)(d + 0.5D);   }
    

    Thank you!

  • help with if else statement and math.random

    Hi a little new to js and need to fill in a text field with the text selected randomly from a range when a button depending on what is put into another text field that is also randomly.

    I really hope that makes sense but here is code that I got so far

    var bg = this.getField("Background").valueAsString;

    var pt_sage = new array();

    pt_sage [0] = 'of the text based on background. "

    pt_Sage [1] = 'of the text based on background. "

    var i = Math.floor (2 * Math.random ())

    var pt_hermit = new array();

    pt_hermit [0] = "text".

    pt_hermit [1] = "text more»

    var v = Math.floor (2 * Math.random ())

    If (bg == 'Wise') {}

    this.getField("PersonalityTraits").value = pt_Sage [i];

    } else (bg == 'Hermit') {}

    this.getField("PersonalityTraits").value = pt_hermit [v];

    }

    I hope someone can help and thanks in advance

    You must change this:

    var pt_sage = new array();

    To do this:

    var pt_sage = new Array();

    Better yet, change it to:

    var pt_sage = ["a text based on the merits," "a text based on the"];

  • Is it possible to use math.random to generate the name of the item web app?

    Math.Random () can be used to auto fill in the name of an element of web application field? I have a client who needs web app point briefs to be random and we do not ask the user to have to create a name for their presentation.

    I think that I thought about it. If anyone is interested:

    I should add that if you try to do, make sure to place your script AFTER the element, you want to be pre-populated. Otherwise, the script will be executed before the load element and it won't work.

  • Upper/lower limits of Math.random

    Hello

    Currently, I applied a random series of my mouse cursor. It fluctuates so on axis Y.

    However, there obviously any value between 0 and 10.

    I like to take 0 or 10.  I know you can use math.round / ceil, but nobody knows how can I do this?

    Thank you.

    var mouseposy = mouseY;

    var mouseposx = mouseX;

    const DURATION: Number = 1;

    const VERTICAL_RANGE:Number = 10;

    var: timer = new Timer (TIME 50 * 20);

    timer.addEventListener (TimerEvent.TIMER, onTimer);

    timer.addEventListener (TimerEvent.TIMER_COMPLETE, onTimerComplete);

    Timer.Start ();

    function onTimer ($event: TimerEvent): void

    {

    myCursor.y = mouseposy - (VERTICAL_RANGE * (Math.Random () * 5));

    myCursor.x = mouseposx

    stage.removeEventListener (MouseEvent.MOUSE_MOVE, OnMouseMoveHandler);

    myCursor.visible = true;

    }

    function onTimerComplete ($event: TimerEvent): void

    {

    x = y = 0;

    stage.addEventListener (MouseEvent.MOUSE_MOVE, OnMouseMoveHandler);

    }

    try to replace these lines

    const VERTICAL_RANGE:Number = 1

    myCursor.y = mouseposy - ((VERTICAL_RANGE * Math.ceil (Math.Random () * 2)) * 10);

  • parameter constraint and math.random height

    I'm a newbie script. I'm doing a script that will...

    1. Take all the items I chose
    2. Scale them down (in height) randomly between 30% and 100% of their original height.

    Here's what I have so far...

    get all the objects currently selected in the document

    selectedObjects var = app.activeDocument.selection;

    reduction of their size by a random number between 0 and 70%

    for (var i = 0; i < selectedObjects.length; i ++) {}

    Gets the height of the current object

    var myHeights = .height selectedObjects [i];

    take the height of the current object and scale of a random percentage

    selectedObjects [i] .height = Math.floor ((Math.random () * myHeights) +. 3);

    }

    And this is what he does, which is excellent...

    ThisPartIsWorking.gif

    But there are two problems, in that I am running...

    [Problem] The height is get scaled compared to the document instead of by the object report. I would like to be able to rotate the object about an axis manually before running the script and still evolve each individual height compared to each object. So far, my script is scaling compared to the document x, y (I think).

    ThisPartIsNotWorking.gif

    I put the pivot point for each of the rectangles in the bottom center, but no dice. In the script, how can I say to use the anchor point of the object to the scaling instead of the document?

    [B problem] I cannot compel the math.random to my values. For example, notice here

    ThisPartIsNotReallyWorking.gif

    that one of the rectangles eventually teeny (less than 30% of the height of the original). How to set constraints on the math.random so that it is easy for me to adjust the settings? Right now I use math.floor but I'm obviously something wrong.

    Any idea?

    I did a quick search and found a function to get a random number.

    Resize allows you to change the height rather than change the height property, which will take care of the problem B.

    //get all the objects that are currently selected in the document
    
    var selectedObjects = app.activeDocument.selection;
    
    //decrease their size by a random number between 0% and 70%
    
    for (var i=0; i
    

    for [A] problem, I would use a different approach. I would start with 1 item (since they are all the same) and duplicate, resize it and turn it as many times as I need to close the loop. We can use a fixed point by using these methods.

  • Loader + Math.Random: why is NombrAl not load random images

    Why this code does NOT load a random image, despite the random number of tracing?

    package {}

    import flash.display.Loader;

    import flash.display.Sprite;

    import flash.events. *;

    import flash.net.URLRequest;

    import flash.display.MovieClip;

    SerializableAttribute public class LoaderExampleTwo extends Sprite {}

    public var randomNumber:Number = new Number();

    private var url: String = "D:/flash cs5.5/flash_help_examples/images/"+randomNumber+".jpg";

    public void LoaderExampleTwo() {}

    NombrAl = Math.ceil (Math.random () * 2);

    trace (randomNumber);

    var loader: Loader = new Loader();

    configureListeners (loader.contentLoaderInfo);

    loader.addEventListener (MouseEvent.CLICK, clickHandler);

    var request: URLRequest = new URLRequest (url);

    Loader.Load (request);

    addChild (loader);

    }

    private void configureListeners(dispatcher:IEventDispatcher):void {}

    dispatcher.addEventListener (Event.COMPLETE, completeHandler);

    dispatcher.addEventListener (HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);

    dispatcher.addEventListener (Event.INIT, initHandler);

    dispatcher.addEventListener (IOErrorEvent.IO_ERROR, ioErrorHandler);

    dispatcher.addEventListener (Event.OPEN, openHandler);

    dispatcher.addEventListener (ProgressEvent.PROGRESS, progressHandler);

    dispatcher.addEventListener (Event.UNLOAD, unLoadHandler);

    }

    private void completeHandler(event:Event):void {}

    trace ("completeHandler:" + event);

    }

    private void httpStatusHandler(event:HTTPStatusEvent):void {}

    trace ("httpStatusHandler:" + event);

    }

    private void initHandler(event:Event):void {}

    trace ("initHandler:" + event);

    }

    private void ioErrorHandler(event:IOErrorEvent):void {}

    trace ("ioErrorHandler:" + event);

    }

    private void openHandler(event:Event):void {}

    trace ("openHandler:" + event);

    }

    private void progressHandler(event:ProgressEvent):void {}

    trace ("progressHandler: bytesLoaded =" + event.bytesLoaded + "bytesTotal =" + event.bytesTotal);

    }

    private void unLoadHandler(event:Event):void {}

    trace ("unLoadHandler:" + event);

    }

    private void clickHandler(event:MouseEvent):void {}

    trace ("clickHandler:" + event);

    var loader: Loader = Loader (event.target);

    Loader.Unload ();

    }

    }

    }

    Try:

    package {}

    import flash.display.Loader;

    import flash.display.Sprite;

    import flash.events. *;

    import flash.net.URLRequest;

    import flash.display.MovieClip;

    SerializableAttribute public class LoaderExampleTwo extends Sprite {}

    public var randomNumber:Number = new Number();

    private var url: String

    public void LoaderExampleTwo() {}

    NombrAl = Math.ceil (Math.random () * 2);

    trace (randomNumber);

    URL = "D:/flash cs5.5/flash_help_examples/images/"+randomNumber+".jpg";

    var loader: Loader = new Loader();

    configureListeners (loader.contentLoaderInfo);

    loader.addEventListener (MouseEvent.CLICK, clickHandler);

    var request: URLRequest = new URLRequest (url);

    Loader.Load (request);

    addChild (loader);

    }

    private void configureListeners(dispatcher:IEventDispatcher):void {}

    dispatcher.addEventListener (Event.COMPLETE, completeHandler);

    dispatcher.addEventListener (HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);

    dispatcher.addEventListener (Event.INIT, initHandler);

    dispatcher.addEventListener (IOErrorEvent.IO_ERROR, ioErrorHandler);

    dispatcher.addEventListener (Event.OPEN, openHandler);

    dispatcher.addEventListener (ProgressEvent.PROGRESS, progressHandler);

    dispatcher.addEventListener (Event.UNLOAD, unLoadHandler);

    }

    private void completeHandler(event:Event):void {}

    trace ("completeHandler:" + event);

    }

    private void httpStatusHandler(event:HTTPStatusEvent):void {}

    trace ("httpStatusHandler:" + event);

    }

    private void initHandler(event:Event):void {}

    trace ("initHandler:" + event);

    }

    private void ioErrorHandler(event:IOErrorEvent):void {}

    trace ("ioErrorHandler:" + event);

    }

    private void openHandler(event:Event):void {}

    trace ("openHandler:" + event);

    }

    private void progressHandler(event:ProgressEvent):void {}

    trace ("progressHandler: bytesLoaded =" + event.bytesLoaded + "bytesTotal =" + event.bytesTotal);

    }

    private void unLoadHandler(event:Event):void {}

    trace ("unLoadHandler:" + event);

    }

    private void clickHandler(event:MouseEvent):void {}

    trace ("clickHandler:" + event);

    var loader: Loader = Loader (event.target);

    Loader.Unload ();

    }

    }

    }

  • Math.Random in a document with Flash Pro class

    Hello.

    in a previous discussion, I had help with randomization of the position of the "appeaance" on an mc on the stage (http://forums.adobe.com/thread/946317?tstart=0), with code is in the file Flash Pro.

    Here, I ask help randomizing positioning using Math.random but by using a class of documents, in order to avoid rewriting the code for the film of many clips I have in the library.

    Clips in the library begin and end with about 15 blank keyframes: they have 2 layers, one for action script and the other for the graphics (which are also filmed sequences,) while the level of the AS in the video clip is longer than the layer containing art, on both ends, beginning and end, so the effect is of bubbles popping up and appearing on the stage in random positions.

    In the library movie clip symbols have a base popBubble.as class, who works at removeChild (this).

    However, using RandomPosBubble.as in the class of document of the flash file, I get a script error-

    D:... RandomPosBubble.as, line 171084: syntax error: expected rightparen before the colon.

    See RandomPosBubble.as below

    package

    {

    import flash.display.MovieClip;

    import flash.events. *;

    SerializableAttribute public class RandomPosBubble extends MovieClip

    {

    public void RandomPosBubble()

    {

    this.addEventListener (Event.ENTER_FRAME, onEnterFrame);

    _spoboyle said - this will set up a listener for the enterFrame event.

    Each image we check if the MovieClip is on frame 1 and if so recalculate its position

    }

    private void onEnterFrame(e:Event):void

    {

    var mc:MovieClip = e.target as MovieClip;

    If (mc:currentFrame == 1)

    {

    MC.x = Math.random () * stage.stageWidth;

    MC.y = Math.random () * stage.stageHeight;

    }

    }

    }

    }

    Thank you.

    the example that I have running does not produce the same model whenever they appear

    Use this as a replacement for the previous Bubble.as file will make them appear at different times

    package
    {
        import flash.events.Event;
    
        public class Bubble extends BubbleMC
        {
            public function Bubble()
            {
                addEventListener(Event.ADDED_TO_STAGE, onAdded);
            }
    
            private function onAdded(e:Event):void
            {
                x = Math.random() * stage.stageWidth;
                y = Math.random() * stage.stageHeight;
                var startFrame:int = Math.random() * 85;
                trace(startFrame);
                gotoAndPlay(startFrame);
                addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
            }
    
            private function onEnterFrameHandler(e:Event):void
            {
                if (currentFrame == 1)
                {
                    x = Math.random() * stage.stageWidth;
                    y = Math.random() * stage.stageHeight;
                }
            }
        }
    }
    
  • Math.Random)

    I want to create a random number between-3 and 3

    In ActionScript, Math.Random () returns a number greater than or equal to 0 but less than 1. Another way to express that is (0<=  n="">< 1)="" where="" n="" is="" the="" number="" you="" are="" looking="">

    To configure a number to fall at random in a range of numbers, use the following format:

    Math.Floor (Math.Random () *(1+High-Low)) + low;

    High is the largest number in your range and low is the lowest number in your range. For example, to get a number between 10 and 50, my line of code looks like this:

    Math.Floor (Math.Random () * 41) + 10;

    This should work for what you want to do:


    Math.Random () * 3 - Math.random () * 3;

  • Explain the math random please

    I am completely confused about exactly how works Math.Random (). Mabye I'm looking for an incorrect code to a random number generator. Could someone please post a simple code which will come with a random number and then show one that number? And then if you could, please explain this code works. Just so I don't have to come back and ask one of these stupid questions! Thank you!

    var r:Number=Math.random();  r is a random number between 0 and 1.

    var s:Number = n + (m - n) * r;  s is a random number between n and m.

    var t:int = Math.round (s);  t is a random integer between n and m

  • Avoid Math.Random () of closure of twice the same number?

    I'm playing a random image gallary by stops to image different every few seconds, and the stock is completely random.

    The problem is, since it has only 5 different images (5 images), I display, there is a high probability that remains to the same frame, how to avoid that? As to avoid staying in the same page twice, if it's not run the new service...?

    //////////////////////////////////////////////////////

    setInterval (createItems, throwItems);

    var RandomImg:randomImg = new randomImg();

    RandomImg.y = 100;

    RandomImg.x = 180;

    RandomImg.gotoAndStop (Math.floor (Math.random () *(1+5-1)) + 1); generate random value between 1 and 5

    addChild (RandomImg);

    //////////////////////////////////////////////////////

    Thank you

    You compare the random value with the current value in your if.  Keep your selection of random frame as a separate function that you can call when you need a new random value... as in...

    var preValue: uint;
    var randomFrame:uint;

    function setRandomValue (): void {}
    randomFrame = Math.floor (Math.random () * 5) + 1;
    }

    function createItems (): void
    {

    while(preValue == randomFrame)
    {
    setRandomValue();
    }

    preValue = randomFrame;

    var RandomImg:randomImg = new randomImg();

    RandomImg.y = 100;

    RandomImg.x = 180;
    RandomImg.gotoAndStop (randomFrame);
    addChild (RandomImg);
    }

  • help with script Math.Random display)

    OK, after help on another thread I managed to get this script


    var r_text = new Array ();
    r_text [0] = "all the leaves are brown;
    r_text [1] = "and the sky is gray."
    r_text [2] = "I was for a walk."
    r_text [3] = "on a winter day.
    r_text [4] = 'I'd be safe and warm. "
    r_text [5] = "If I is in L.A."
    r_text [6] = "California dreaming, such a winter day;
    var i = Math.floor (7 * Math.random ())

    document. Write (r_text [i]);

    who will work on webpages when updated, but I need it to operate when a button is pressed and displayed in a text field in my pdf

    I'm a total noob with javascript only to start learning today so as much help that pos will be great thanks in advance

    Instead of this line:

    document. Write (r_text [i]);

    You need to use something like this:

    this.getField("Field_name").value = r_text [i];

    Or if you use it as the custom text field calculation script:

    Event.Value = r_text [i];

  • Is there a way to create a math.random that don't overlap movieclips?

    Hello

    In fact, I have two questions. I create a sequence memory game and I was wondering:

    1. is there a way to movieclips random position on the stage without overlap?

    2. is there a way to have flash draw a vector from one clip to another in the order, and then create a user trace what flash has done? I have 6 clips on the stage, each with their own instance (e.g. obj1_mc, obj2_mc, etc.). Is there a way to tell flash always draw a line between movieclips in sequence, even if the clips are placed randomly on the stage?

    Thank you

    JO

    you don't know.

    1. the best way to position objects without too much running, IF you can assume it will always be possible, is to use something like:

    var mcA:Array = [your movieclips]

    var: index: uint = 0;

    positionF();

    function positionF() {}

    assuming that the points of top-left reg of your movieclips

    mcA [index] .x = Math.random () *(stage.stageWidth-mcA[index].width);

    mcA [index] = Math.random () *(stage.stageHeight-mcA[index].height) there;

    var hitBool:Boolean = false;

    for (var i: int = 0; i<>

    {if (mcA [index] .hitTestObject (mcA [i]))}

    hitBool = true;

    break;

    }

    }

    {if (hitBool)}

    positionF();

    } else {}

    index ++;

    If (index<>

    positionF();

    } else {}

    localization complete.  No matter what

    }

    }

    }

    2. you can use the graphics class to draw dynamic lines.

  • Table Math.Random &amp; Delete?

    Can someone help me with the following random number script?

    simplified example:

    I have 10 dynamic textfield to display numbers. named myNumber1_txt, myNumber2_txt... myNumber10_txt

    I have 100 numbers

    //

    for (var i: int = 0; i < 10; i ++) {}

    Result: var number = Math.floor (Math.random () * 100) + 1;

    trace (Result);

    }

    myNumber1_txt.text = "" + result;

    etc.

    //

    This works great – but what I'm trying to achieve is to delete the number that appears already in one of the object textfield, so no double numbers are disclosed.

    so, if myNumber1_txt.text = 10, that 10 will not be calculated the random number more in the rest of the textfields and so on.

    Is there an easy way to achieve this?

    I tried with the delete table... but is not well run.

    Thank you!

    Play with the following code... basically you fill a table with figures, tests to ensure that the value is not already in the table.

    var randNums:Array = new Array();

    for (var i: int = 0; i<10; i++)="">
    var randNum:int = Math.floor (Math.random () * 100) + 1;
    If (randNums.IndexOf (randNum) ==-1) {/ / don't NB in the table so add and assign to textfield}
    randNums.push (randNum);

    This ["myNumber" + (i + 1) String "_txt"] .text plus String (randNum);

    } else {/ / already number in the table}
    i-- ;
    }
    }

Maybe you are looking for