Generate multiple random numbers?

Hi,
I'm trying to generate random numbers using Math.random()* n;
but I want the random numbers to reset to something different after
a particular event is called. Instead, I've noticed the numbers
either buzz away randomly in every frame (when placed inside
onEnterFrame), or it picks random numbers once, and then uses those
same values over and over (when placed outside the onEnterFrame).
How do i get actionscript to generate new random numbers
after each myMC.onPress = function(), or alternatively, after a
score changes (like some kind of watch feature?)

ok, i've got a half working version;
function ranbot(x) {
return Math.ceil(Math.random()* x) + "/" +
Math.ceil(Math.random()* x);
trace(ranbot(60));
but is it possible to set up the function so the numerator is
equal to or less than the denominator? Also, if the numerator is
set to never exceed the denominator, then a large percentage -
something like 25-50% of the output fractions would equal "1", like
55/55, 23/23, 7/7, 28/28, and so on.
I did something like this when using variables;
var randombot2:Number = Math.ceil(Math.random()* 99);
var randomtop2:Number = Math.min(randombot2 -
Math.floor(Math.random()* randombot2* 0.5),
Math.ceil(Math.random()* 99));
- but I do not understand how this works in function
terminology.

Similar Messages

  • How can you generate Multiple random numbers from 1 to 49?

    I am very new at programming with the iPhone SDK and I need some help with a project I am working on. What I want to do is set up a window with 6 labels and 1 button. When the user clicks the button, the program will populate 6 randomized numbers each ranging from 1 to 49, and then place each of 6 numbers in a label. But each time the program ends and starts again the numbers cannot be the same, and also when the user clicks the button, no label can have the same number twice, so for example. If label 1 had the number 10, the other 5 labels cannot have that number until the button is clicked again. I know how to set up the interface, I just need the code. I would so greatly appreciate someone's help in this matter. I have been trying to do this for days and I cannot figure it out. Possibly someone who knows tons about Objective C programming can help me!
    Thank-you so very much!!

    I see that you're writing a lottery number generator. Perhaps the easiest way to do it is to emulate a real lottery: fill an array (NSMutableArray, probably) with the numbers between 1 and 49, pick one at random, remove that number from the array, and repeat. (You can think of the numbers as being the balls and the array as being the machine that pops them out.)
    One simple way to get the random indices needed is to extract six random bytes from Randomization Services using SecRandomCopyBytes, then loop over them, using the modulo operator (%) to select an index within the size of the array.
    And no, I'm not going to write your code for you. If I was going to do that, I could package and sell the app myself.

  • How do you generate multiple random numbers between 1 and 49

    I am new at mac programming and I want to make an iPhone app with the free SDK. What I would like to try is a random number generator. I imagine it as when the user clicks a button 6 random numbers from 1 to 49 would appear in a label or another control. If someone could please give me the code that would place these randomized numbers in a label I would greatly appreciate it. I know how to link all the controls together, I just need the code. Thank-you to anyone that can help!

    semi-sudo code goes here
    --prepare and array which will have number from 0 to 49
    --loop thru the array like this
    int i=0
    for (i; i<=49; i++) {
    int a=arc4random() % 49] ;
    int b=arc4random() % 49];
    --here exchange the objects so that they are shuffled
    [myArray exchangeObjectAtIndex:a withObjectAtIndex:b];

  • Generate the random numbers

    How Do I Generate Random Numbers in iWorks
    Excel has the "F9" key to generate random numbers numbers don't
    please see below what i'm trying to do
    I open up a blank Excel worksheet, and type the number "1" into cell A1. Type the number "2" into cell A2. Then type the number "3" into cell A3. Type the number "4" into cell A4, and then type the number "5" into cell A5.
    2
    Type the word "PB" into cell A6.
    3
    Enter the function "=RANDBETWEEN(1,59)" into cell B1.
    4
    Enter an exact copy of this function "=RANDBETWEEN(1,59)" into cells B2, B3, B4, and B5.
    5
    Enter the function "=RANDBETWEEN(1,39)" into cell B6.
    6
    Hit the "F9" key to generate the random numbers simulating game.
    But in numbers how do i do this?
    Thanks!
    Alex...

    firstly your not asking about generating random numbers, your asking how do you make a workbook recalculate new random numbers. From M$'s website:
    F9
    Calculates all worksheets in all open workbooks
    It does not produce random numbers the equations should produce random numbers as soon as you enter them in. If they dont then you have automatic reclaculations turned off and F9 is forcing a recalc.
    In numbers there is not shortcut to forcing the workbook to recalculate other than enter data into a cell. So if you made a new table and then enter data. For every data point you enter you should see new data apear.
    Was just validating the method for forcing and its not working on my ipad. I will mark this conversation and if i find it i will respond again.
    Jason
    Message was edited by: jaxjason

  • How to generate unique random numbers

    Hi All,
    I am wondering whether there is already a random library or built-in function available in Java to produce some random numbers between certain ranges that are not repetitive. Let's look at a common examples as follows:
    Random diceRoller = new Random();
    for (int i = 0; i < 10; i++) {
      int roll = diceRoller.nextInt(6) + 1;
      System.out.println(roll);
    }My understanding from this approach is that it allows the same number to be repeated over and over again. However, I would like to find out how to continue generating random numbers from remaining ones that haven't been generated earlier.
    Using the above example to illustrate my intention:
    1st random number generated - possibility of 1 - 6 showed up. Say 5 is picked.
    2nd random number generated - possibility of 1, 2, 3, 4, 6 only. Say 2 is picked.
    3rd random number generated - possibility of 1, 3, 4, 6 available. Say 1 is picked.
    4th random number generated - possibility of 3, 4, 6 left. Say 6 is picked.
    5th random number generated - possibility of 3, 4 remains. Say 4 is picked.
    Any assistance would be much appreciated.
    Many thanks,
    Jack

    htran_888 wrote:
    Hi All,
    I am wondering whether there is already a random library or built-in function available in Java to produce some random numbers between certain ranges that are not repetitive. Let's look at a common examples as follows:
    Random diceRoller = new Random();
    for (int i = 0; i < 10; i++) {
    int roll = diceRoller.nextInt(6) + 1;
    System.out.println(roll);
    }My understanding from this approach is that it allows the same number to be repeated over and over again. However, I would like to find out how to continue generating random numbers from remaining ones that haven't been generated earlier.
    Using the above example to illustrate my intention:
    1st random number generated - possibility of 1 - 6 showed up. Say 5 is picked.
    2nd random number generated - possibility of 1, 2, 3, 4, 6 only. Say 2 is picked.
    3rd random number generated - possibility of 1, 3, 4, 6 available. Say 1 is picked.
    4th random number generated - possibility of 3, 4, 6 left. Say 6 is picked.
    5th random number generated - possibility of 3, 4 remains. Say 4 is picked.
    Any assistance would be much appreciated.If it is your school assignment then you have the answer above (List & the lists length).
    (You might want to look at Collections)

  • Generating negative random numbers

    Hi,
    I'm trying to generate random float numbers between -1 and +1. But the nextFloat() method of the Random class supposedly only generates floats between 0.0f and 1.0f.
    How do I generate floats between 0.0f and -1.0f?
    Please help?
    Thanks.

    Right... I just figured out that if you want a random number in the range (m,n) you use
    x=(n-m)*(getNextFloat())+m
    so in the range(-1,1) you have (1-(-1))*getNextFloat()+(-1)
    =2*getNextFloat()-1

  • How can I generate multiple unique random numbers?

    Hello,
    I am trying to generate multiple random numbers between a given set of numbers (1-52) and not have the same number generated twice within that set. I can compare the last and next numbers with the compare function but how would I go about comparing all of the generated numbers without using a huge list of shift registers...
    Any help/ideas are welcome and appreciated.
    Jason
    Solved!
    Go to Solution.

    Here is an implementation of Jason's solution.
    steve
    Help the forum when you get help. Click the "Solution?" icon on the reply that answers your
    question. Give "Kudos" to replies that help.
    Attachments:
    random.vi ‏10 KB

  • Random numbers without using java funtions

    i need a formula to generate 100 random numbers 1-20
    any suggestions?

    Doesn't need much explaining. Did you try it?
    http://www.google.com/search?q=RNG+algorithms&sourceid=mozilla-search&start=0&start=0&ie=utf-8&oe=utf-8

  • Need help with random numbers

    hi i need to generate 2 random numbers from array list . and then take out that two numbers from list.
         String[] plcard = { "AC", "KC", "QC", "JC",
              "10C", "9C", "8C", "7C","6C","5C","4C","3C","2C", "AD", "KD", "QD", "JD",
              "10D", "9D", "8D", "7D","6D","5D","4D","3D","2D", "AS", "KS", "QS", "JS",
              "10S", "9S", "8S", "7S","6S","5S","4S","3S","2S", "AH", "KH", "QH", "JH",
              "10H", "9H", "8H", "7H","6H","5H","4H","3H","2H",};
    this is the list if someone can help me i would appreciate
    thanks in advance

    haha, never noticed the .shuffle(List) method!
    maybe java is getting too convenient (just kidding)?
    i never wrote a card game.
    how would the more programmingly gifted of us do this?
    this is my shot at it for what its worth...
    public class Card{
    public Card(int rank, int suit){
    this.rank = rank;
    this.suit = suit;
    int rank (or String i suppose)
    int suit;
    static final club = 1;
    static final spade = 2;
    static final heart = 3;
    static final diamond = 4;
    public class Shuffler{
    public Shuffler(){
    int NumOfDecks = 1;
    Vector ShuffledDeck;
    // num of decks
    for(int i = 0; i < NumOfDecks){
    // 4 suits
    for(int j = 0; j < 4; j++){
    // 13 ranks
    for(int k = 0; k < 13; k++){
    ShuffledDeck.add(new Card(k, j));
    } // suits
    } // num of decks
    Collections.shuffle(ShuffledDeck);
    // Done?
    }

  • How to generate sepecific serial numbers?

    We want to generate specific serial number for item from paraemters, don't want to use the prefix or start number of item attribute.
    Serial Number should generated not associated with transactions. And Item attribute defined as "PRE-DEFINDED"
    And we do not want to insert basis table MTL_SERIAL_NUMBERS.
    We need API or Interface to do this.
    Is there anyone can help me?

    randy_ortan wrote:
    How to generate unique random numbers with out repetitions.The simplest way is to load the numbers 1 to 9 into an ArrayList. Then you use the Collections.shuffle method to shuffle the ArrayList numbers into random order. Finally you pick the 5 first numbers in the ArrayList. They will be unique and randomly picked from the 1 to 9 interval.
    If you want another 5 numbers you just reshuffle the ArrayList and pick the 5 first numbers again.

  • How do i generate a random letters?

    for my end of the year project i need to create a program that is essentially a guessing game... it randomly generates 3 seperate letters, and i have to guess them, how do i do this? the generation part
    plz someone help me out, i really need this credit....email me or hotmail me @
    [email protected]
    thanks so much guys

    What I'd do is generate 3 random numbers between 1-26, then corrispond those to letters. ASCII would be the easiest way.
    for my end of the year project i need to create a
    program that is essentially a guessing game... it
    randomly generates 3 seperate letters, and i have to
    guess them, how do i do this? the generation part
    plz someone help me out, i really need this
    credit....email me or hotmail me @
    [email protected]
    thanks so much guys

  • Figuring out the occurence of random numbers?

    So, I'm taking this Computer Science class, and I've been struggling so much with today's lesson.
    For this particular question, I have to get 20 random numbers between 1-5, represent them in text format, and the show how often each of the numbers occured. I've done the first two of the three parts, but this last part really has me stumped..
    (Note: I'm using Ready to Program by Holt.... so I'm using their console)
    Here's the code I got so far:
    import java.util.*;
    import hsa.Console;
    import java.io.*;
    public class RandomNumbers
        static Console c;
        static public void main (String[] args) throws IOException
            c = new Console ();
            int a;
            Random generator = new Random();
            c.println("Generating Numbers: ");
            for(a=1;a<=20;a++)
                int r = generator.nextInt(5)+1;
                    switch(r)
                         case 1: c.print("One",10); break;
                         case 2: c.print("Two",10); break;
                         case 3: c.print("Three",10); break;
                         case 4: c.print("Four",10); break;
                         case 5: c.print("Five",10); break;
    }}

    I had a similar assignment my last semester for C++. I would think the general idea is the same.
    Here I declare an Array. Then I store the values of the dice rolled in the array and display it on the screen. The syntax will be different since you are not using C++.
    #include <iostream>          // preprocessor directive
    #include <ctime>          // preprocessor directive
    #include <cmath>          // preprocessor directive
    #include <cstdlib>          // preprocessor directive
    using namespace std;     // enables preprocessor directives
    int random_int(int a, int b);          // function prototpye
    int main ()     // main function
         srand(time(NULL));          // enables random numbers to be generated
         int d1, d2, sum;                         // declaring variables
         int a[10] = {0,0,0,0,0,0,0,0,0,0};     // initializes valus in array to 0
         int roll;                                   // declaring variable
         cout << "Roll how many times?";          // ask number of times to roll dice
         cin >> roll;                              // get number of times to roll dice
         for(int i=0; i<=roll; i++)               // to roll the dice the numbers or times asked
              d1 = random_int(1,6);               // generates number for die 1
              d2 = random_int(1,6);               // generates number for die 2
              sum = d1 + d2;                         // adds the two dice together     
              if(sum == 2)                         // increase value in array  by 1 that corresponds to 2
                   a[0]++;
              else if(sum==3)                         // increase value in array  by 1 that corresponds to 3
                   a[1]++;
              else if(sum==4)                         // increase value in array  by 1 that corresponds to 4
                   a[2]++;
              else if(sum==5)                         // increase value in array  by 1 that corresponds to 5
                   a[3]++;     
              else if(sum==6)                         // increase value in array  by 1 that corresponds to 6
                   a[4]++;
              else if(sum==7)                         // increase value in array  by 1 that corresponds to 7
                   a[5]++;
              else if(sum==8)                         // increase value in array  by 1 that corresponds to 8
                   a[6]++;
              else if(sum==9)                         // increase value in array  by 1 that corresponds to 9
                   a[7]++;
              else if(sum==10)                    // increase value in array  by 1 that corresponds to 10
                   a[8]++;          
              else if(sum==11)                    // increase value in array  by 1 that corresponds to 11
                   a[9]++;
              else if(sum==12)                    // increase value in array  by 1 that corresponds to 12
                   a[10]++;
         for(int j = 2; j<=12; j++)                    
              cout << j << "  " << a[j-2] <<endl;          // output the array
         return 0; //exit program
    int random_int(int a, int b)          // used to generate te random numbers
         int random = rand()%(b-a+1) + a;
         return (random);
    }          

  • Non repeating random numbers

    Hi,
    Im writing code to generate 10 random numbers and i have code written so that if a number between 1 and 10 is already chosen, it has to look for another number. heres snippets of the code:
    for (int b = 0; b < 2; b++)
    for (int i = 0; i < a.length; i++)
    int test = (int)(Math.random() * 10);
    boolean r = valueExists(test);
    if (r == (true))
    test = (int)(Math.random() * 10);
    else
    a[i] = test;
    boolean valueExists(int value)
    int z = a.length;
    boolean exists = false;
    for (int j = 0; j < z; j++)
    if (a[j] == value)
    exists = true;
    return exists;
    when i run this code, the numbers do repeat. can anyone help?

    import java.util.List;
    import java.util.ArrayList;
    import java.util.Random;
    public class RandomNumbersDemo {
        private List numbers = new ArrayList();
        private Random random = new Random();
        public static void main(String[] args) {
                 RandomNumbersDemo demo = new RandomNumbersDemo();
            demo.init();
            demo.doThatVoodoo();
        public void doThatVoodoo() {
            while (numbers.size() > 0) {
                System.out.println(getRandomInteger());
        public int getRandomInteger() {
            int element = random.nextInt(numbers.size());
            Integer randomInteger = (Integer) numbers.get(element);
            numbers.remove(element);
            return randomInteger.intValue();
        public void init() {
            for (int i = 0; i < 10; i++) {
                numbers.add(new Integer(i));

  • FPGA 20 random numbers

    Hello,
    I have NI PXIe-7966R FPGA module and i want to generate 20 random numbers with specified distribution. Now i have random number generator with uniform distribuiton and i have quantile function for my distribution in the form of 1000 point array. It takes a lot of logical blocks of FPGA if Im trying to solve this problem with 20 lookup tables or 20 memory blocks with my quantile function. Can you help me to advice?

    Theres an example on NI.com that uses the method outlined in this paper from xilinx. 

  • Random numbers addition 1

    Hello,
    Please can you help me to generate a serie of independant random number, their sum should be equal to one and able to reach the extremities.
    I give 2 examples of a serie of 5 number
    0.1   0.6  0.01 0.2  0.09  =1 
    0.01   0.01  0.05  0.02 0.91  =1
    I have a VI attached able to generate these random numbers but they are very near to each others. I give an example
    0.3   0.2   0.1  0.35  0.05  =1
    Thanks,
    Attachments:
    random.zip ‏13 KB

    Your main problem is that the mean of your samples must be 1/N, where N is the number of samples.  This will lower what you can get for an upper extreme.  I'd talk to your math expert and ask him for an algorithm that can do this and then we can code it up.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

Maybe you are looking for

  • Goods Receipt Indicator- (PO under Delivery Tab)

    I want set Goods Receipt Indicator in Purchase order under Delivery tab for specific company code. What are the configuration setting for GR Indicator default in Purchase order. I know OME9 apart from that is there any other way. thanks in advance

  • How do you make a video file acceptable to Captivate 7?

    I tried to attach a video and although the video was an .mp4, Captivate wouldn't allow it.  I downloaded the FLV Converter, but it still won't accept the file.

  • Down Pmnt Request - Out put - Urgent

    Hi all of you I have configured the Down payment process for both customers and vendors .. But thing is that when iam raising request for down paymnet for customer iam not getting the output. My client is asking the request output to sent to the cust

  • Urgent! How to use push_pred to optimize query with UNION in 10g?

    Hi, We are facing slow query performance in 10g database. Appreciate if anyone could advise on how to optimize the performance by using push pred? Or is there any other ways. Thanks in advance. Cheers, SC

  • Trigger a File

    Hi all, I need to trigger a empty file Trigger.txt if and only if the files are transported to the destination folder. Its mere a file to file scenario. How can i do that? pls explain me. Regards, Kanda