Random number in range generator plz help!

hey hope someone can help me out, im sure its an easy one:
var tstArray:Array = new Array(1,2,3);
for (var a:uint=0; a<tstArray.length; a++)
var x:Number = Math.floor((Math.random()*tstArray[a]));
trace(x);
tstArray.splice(a,1);
i have this code but it doesnt do exectply what i want it to do. Im trying to generate a signle random number per click between 1 and 3 and when all numbers have been used up, remove this click listener.
if u can help it'll be much appriciated
thx pavel

use:
var fp1:farm_part1=new farm_part1();
and any time you want to randomize an array use:
var tstArray:Array = fp1.randomizeF([1,2,3]);
package
*/import flash.utils.Timer;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.*;
import flash.media.Sound;
import flash.events.TimerEvent;
import flash.media.SoundChannel;
import flash.media.SoundTransform;*/
public class farm_Part1
public function randomizeF(a:Array):Array
{a.shuffle();
return a;
///////////////////////////// change nothing below /////////////////////////////////////////
function shuffle(a:Array)
var p:int;
var t:*;
var ivar:int;
for (ivar = a.length-1; ivar>=0; ivar--)
p=Math.floor((ivar+1)*Math.random());
t = a[ivar];
a[ivar] = a[p];
a[p] = t;
}//randomAnimal
}//class
}//package

Similar Messages

  • Generate 3 digits floating point random number

    hai....How I want to generate 3 digits floating point random number??..plz help me...
    Thanks..

    Hi gdah,
    use some common math functions to get a randopm number in the range from 1 to 5 (but not including 5, see help for "random number"!)... Then format to a string (if needed) or set properties of numeric indicator...
    Hey Mike, your first version looked quite different
    Message Edited by GerdW on 05-05-2008 09:39 AM
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    RND_1-5_3Digits.png ‏1 KB

  • 7 digit unique random number

    I would like to generate 7 digit unique random number. I have it something like this :
    Random generator = new Random();
              generator.setSeed(System.currentTimeMillis());
              //generates seven digit random number.
              return generator.nextInt(9999999) + 999999;
    But it generates 8 digit numbers sometimes. I am giving the Max limit in the braces and min limit after the "+" sign. Could anybody help me figure out what is wrong.

    This is not a horrible solution but an intelligent &
    easy solution ;)Actually this would be the easy and intellegent solution to the problem "give a random 7 digit integer."
    Random generator = new Random();
    //generates seven digit random number.
    return generator.nextInt(10000000);Though the orginal post does not specify this as part of the problem others have assumed (probably correctly) that in fact the poster wants a number between 1000000 and 9999999 (inclusive) which can easily be produced with the following modification to the above.
    Random generator = new Random();
    //generates seven digit random number.
    return generator.nextInt(9000000) + 1000000;I am confused by your response. Are you saying the becasue the original question was asking why flawed code doesn't work, that makes your solution good?

  • Need help with a JavaScript to generate random number

    Hi
    First things first. I don't know the J of JavaScript.
    When I was thinking of some readymade solution to generate a random number in Captivate, I found this on a LinkedIn forum.
    1) Add a user variable to your project called "randomNumber". It's value can be zero.
    2) Add a Text Caption with "$$randomNumber$$" in it, to check whether your script is working.
    3) Add a button to the slide. Give it an On Success Action of Execute JavaScript. Turn off it's "Continue Playing the Project" checkbox.
    4) Add the following text in the button's Script_Window:
    var objCP = document.Captivate;
    var rand = 1 + Math.floor(Math.random() * 10);
    function onButtonClick(){
    objCP.cpEISetValue('randomNumber', rand);
    onButtonClick();
    However, this is (as the poster in the forum warned) not working for Captivate 7. Can somebody please help?
    I am open for any other methods of getting the same result.
    Thanks in advance,
    Sreekanth

    Hi Sreekanth,
    When testing, make sure you are testing from a web server where the web address begins with http or https.  When setting the captivate variable "randomNumber" try this instead:
    objCP.cpEISetValue('m_VarHandle.randomNumber', rand);
    That will only work for SWF output.  If you want it to work for both HTML5 and SWF output, try this code:
    window.onButtonClick = function(){
              var rand = generateRandomNumber(1, 10);
              setCpVariable('randomNumber', rand);
    window.generateRandomNumber = function(min, max){
              var randomNum = 0;
              if(!isNaN(parseFloat(min)) && !isNaN(parseFloat(max))){
                        min = Number(min);
                        max = Number(max);
                  randomNum = Math.floor(Math.random() * (max - min + 1)) + min;
              return randomNum;
    window.setCpVariable = function (cpUserVariableName, variableValue) {
              /* Check for HTML5 vs. SWF output */
              if (typeof window.cp === 'undefined') {
                        /* We have SWF output, so Get the Captivate Object */
                        var objCp = document.getElementById('Captivate');
                        if (objCp && objCp.cpEISetValue) {
                                  /* Set the Captivate User variable with the JavaScript variable, variableValue */
                                  objCp.cpEISetValue('m_VarHandle.' + cpUserVariableName, variableValue);
              } else {
                        /* We have HTML5 output */
                        /*If variable does not exist off of the window object, then use the variables manager*/
                        if (typeof window[cpUserVariableName] === 'undefined') {
                                  if (cp.vm && cp.vm.setVariableValue) {
                                            cp.vm.setVariableValue(cpUserVariableName, variableValue);
                        } else {
                                  window[cpUserVariableName] = variableValue;
    window.onButtonClick();
    Be sure to test this from a web server or else local security will prevent the javascript from executing.
    Best,
    Jim Leichliter

  • Help: JSP Random Number Generator

    hello every one,
    Im trying to generate a random number using currentTimeMillis(), in Jsp, can you help me out and advice me how can this be done please.

    First you say you want a random number, then you say you want a unique one. Which is it?
    Random numbers do not normally guaruntee uniqueness.
    is there away i could use the currentTimeMillis(), What would you use it for? System.currentTimeMillis() is commonly used as a seed for a random number generator. The java.util.Random class uses it like that - take a look at that API link.
    Or if its a homework question state the exact requirement - I'm guessing here.

  • Help for random number generator???

    hi there can anyone how to make simple random number
    generator for slot machine , formula for chances in probability ,
    or simple random number generator for slot machine , thanks
    :)

    actualy the accurate RNG for slot machine ?? any idea?

  • Random NUMBER generator help..

    Hi all,
    i'm having issues with my random number generator i'm trying to fill my array with random numbers but i keep getting it filled with zeros.... can any one tell me what i'm doing wrong i can;t figure it out..
    for (int i =0; i < 100; i++){
                        int x=(int) (Math.random());
                        data[i] = x;
    }

    From the API "Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0."
    So casting the value to int is always going to result in a zero value.
    You need to multiply by a value that is one larger than the value you want to be your maximum. For example:
    int x = (int)(Math.random() * 100);
    should create a random number from 0 to 99

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

    Build a VI that generates a random number between 1 and 80 
    Divides the random number by a number specified in the front panel.
    If the inputted number is zero, the VI program should turn on a LED in the front-panel to indicate a divide by zero error.
    Solved!
    Go to Solution.

    One quick question Edward, was the answer just in time for your monday morning class.
    Ton
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!

  • Generating N-digit random number??

    Hi All,
    I need to generate N-digit random number, anyone can help me?
    Thx in advance b4...

    import java.util.*;
    public class Try{
         public static void main(String []args){
              for(int i=0;i<100;i++){
                    System.out.println((int)(Math.random() * 10));
    }Yes I saw the casting, no problem with it, but I did used it alot to generate me number between a range of 1 - 9
    and if you want a range of 1 - 10, i just put a
    1+(int)(Math.random() * 10)

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

    I am trying to simulate data without using a DAQ device by using a random number generator and I want to be able to control the "range" of the random number generated though.  On the front pannel, the user would be able to input a nominal number, and the random number generator would generate numbers within plus or minus .003 of that nominal number.  The data would then be plotted on a graph.  Anyone know how to do this?  Or if it's even possible?
    Just for information sake, the random number is supposed to look like thickness measurements, that's why I want to simulate plus and minus .003 because the data could be thinner or thicker than the nominal.  
    Thanks in advance!!
    Solved!
    Go to Solution.

    You can create a random number with a gaussian probability profile using two equal distributed (0...1) random numbers and applying the Box Muller transform.
    I wrote one many years ago, her it is. (LabVIEW 8.0). 
    Message Edited by altenbach on 04-12-2010 09:13 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    BoxMuller.vi ‏10 KB

  • Generate a random number and make it STAY after "save"

    I searched around this forum and found that I can use this code to generate a random number:
    //this.rawValue = Math.round(Math.random() * 1000000);
    Works great. only problem is, once I practice on the "real" form and save, close, and reopen - it changes the random number every time. I need to figure out a way to make it save the 1st number it generates when someone opens the form and types info in it....then they save and close, etc.
    Can anyone help me? Thanks!!

    Example steps:
    1. Add a hidden field to the same subform with name 'hiddenField'.
    2. First time you open 'hiddenField' rawValue will be null.
    3. where ever you run the code to generate random number use scenario like this.
    if (hiddenField.isNull) {
    this.rawValue = Math.round(Math.random() * 1000000);
    }else {
    this.rawValue = hiddenField.rawValue;
    Hope this thelps.
    SekharN

  • Updating a field that generates random number when form is reset..

    I have a field that will generate a random number when the form is initially opened. THis fiekd runs an initialization script of : var randomnumber=Math.floor(math.random()*99999) and then a calculation script of randomnumber.
    The field value is set as Calculated - Read Only.
    When I hit the Reset button and it clears all the input fields for the form i would like to have it re calculate a new random number. I am not knowledgable in any scripting language and what I have so far I found by searching the forums.
    Any help would be appreciated.
    Thanks

    I don't know if it should matter, but the field to update is on a page other than the one with the reset button. And, the above is not working.
    I tried it as you stated above fieldname.rawvalue=randomnumber and I tried pagename.fieldname.rawvalue=randomnumber

  • Random Number Generator setSeed(); method???

    I've searched and can't get a good understanding of the setSeed() method. I am suppose to use the loop control variable to seed the random number generator inside the loop. I need to use the same input everytime I use the random generator. When I compile it says int cannot be dereferenced.
    for(int i = 0; i < array.length; i++)
    int randnum = generator.nextInt(100);
    randnum.setSeed(i);
    array[i] = randnum;
    If anyone can explain the setSeed() method that would be greatly appreciated. Thanks!

    badbro wrote:
    Thanks for your help, but leave the smart comments to yourself. They are not needed. Thats what this forum is for.All of Paul's comments were dead spot on, and if you listen to him and take his advice to heart, it will only help you. If they make you upset, well then that's your problem, isn't it? My advice: grow up.

  • Random number generator. Even and odd numbers

    I have a problem.
    I have a random number generator, it goes from 0 to 20, I need to have two indicators, one will show how many numbers are pairs, and how many are not.
    I tried to use the decimated 1D array, but since those numbers are random, it doesn´t work for me. I´m new with LabView, and I don´t know if there is some other way to make it work, I need some help, especially with some examples.
    Thank you so much.
    Solved!
    Go to Solution.

    RavensFan wrote:
    Spoiler (Highlight to read)
    Create the array.  Use quotient remainder to divide by 2.  Now you have an array where all the odd numbers are now 1, and all the even numbers are now 0.  Sum the array and you have the total number of odd numbers.  The number of evens will be the length of the array divided by the # of odds.
    Create the array.  Use quotient remainder to divide by 2.  Now you have an array where all the odd numbers are now 1, and all the even numbers are now 0.  Sum the array and you have the total number of odd numbers.  The number of evens will be the length of the array divided by the # of odds.
    Haha I lost sight of the fact that he was looking for the amount off odds and evens.  Good one.
    Bill
    (Mid-Level minion.)
    My support system ensures that I don't look totally incompetent.
    Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

  • Does Labview have a Random Number Generator for U16 with a periodicity greater than 64 Million instances of U16words and one with SEED as the connector?

    We are doing some testing that requires 64MegaWords be written to our DSP memory  with random values to do a validity check and without repeating sequences with using the previous value as the seed for the next and us passing it the initial seed.  The dice one doesn't meet that criteria, and I was not sure how the continuous random number generator parameters work and if any of them would meet this criteria. Anyone have any information that might help?
    Thanks,
    Sue

    Hi suem,
    There is no reason why you couldn't simply write a pseudo-random number generator by yourself. Simply select a random number algorithm you want to use and implement it in LabVIEW. You do not need to interface code written in another language in order to implement a pseudorandom number generator. If you have a DAQ card or something, you can also use inputr noise or some other hardware soruce to generate real random numbers. For that also LabVIEW is an excellent tool.
    Tomi
    Tomi Maila

Maybe you are looking for

  • L&F error when starting application on Mac OS 10.3.5

    I'm trying to execute a Java application I'm developing on Mac OS 10.3.5. But I keep getting this error: Richard@cthulu( 18 )$ ant java.alone Buildfile: build.xml (... snip ...) java.alone: [java] java.lang.Error: can't load apple.laf.AquaLookAndFeel

  • No connections in the combo box of Infobus Data Form Wizard?

    I am trying to create a new project but when I try and select a connection, the "Connection" drop-down combo-box is empty. I have created 9 connections, but cannot select them. I have tried adding a new one and editing but still they do not appear. A

  • Viewing Size while composing messages

    How do I change the appearance size of fonts while composing emails- not change font size of message itself

  • Unknown error (-39) = cannot sync iPod Nano 3rd gen.

    Hi There, Got an Imac G5 PPC with OS 10.5.2 and the latest version of iTunes and so. I use 2 nike plus kits (my wife and myself) on 1 iPod and 1 Imac. Each time when synching I get error (-39). Anybody familiar with error-numbers as -39? Inspite I ha

  • Metro Ethernet implementation questions

    I am planning a Metro Ethernet upgrade for a network I manage. This is the first time I've implemented Metro on any network. I'm looking for some suggestions and answers to a couple questions regarding this upgrade. The current network is Hub and spo