Random Numbers Question

I'm working from a chapter in Gary Rosenzweig's
ActionScript 3.0 Game Programming University. In this
example 36 random cards are created and placed on the stage. I
understand most of the code except for this line:
thisCard.cardFace = cardList[r]; The line above the one I
just mentioned assigns a random value to r and I don't understand
how the computer knows it's not assigning a value to cardFace that
already exists? Since this function is iterating several times
wouldn't it be possible for one of the random numbers to be
repeated?
Joe

yes, one card is deleted. that card is thisCard.cardFace.
it's just like dealing cards. when you deal an ace of clubs
to someone, that card is removed from the deck. any card dealt
after that is randomly selected from the remaining cards.
the code above is more akin to organizing a deck of cards
with the ace of clubs on top, king of clubs beneath, queen of
clubs,...,2clubs,ace of diamonds,...,2diamonds,...,2spades. then
pick a random number between 1 and 52, select that card number and
remove it from the deck. now pic a random number between 1 and 51
and remove that from the dect. etc.

Similar Messages

  • Can't validate outlook on iPad - random numbers and letters don't display - only a question mark in a blue box

    If I have to validate Outlook on PC or Mac - I have no problem - the random numbers and letters display fine - but if I am requested to validate outlook before sending a mail when using my iPad, the operation fails as the test numbers and letters are not shown - only a snap blue box with a question mark.  How do I convert the box into the image of a new validation code?  Thanks in advance.

    Hello,
    The question mark means it can't find it where it was when you put it in the Dock.
    I'd get EasyFind...
    http://www.macupdate.com/info.php/id/11076
    Use it to search your whole drive for Files & Folders, case insensitive & show invisibles...
    Complete
    That will show any with that word in the name at all.

  • HELPwith array of random numbers!!!

    can anyone please write up a program that uses an array of random numbers from 0-100 and sort them out...
    if anyone can help me that would be great...i tried but i cannot figure it out...
    please just write the program so I just have to copy and paste :)

    This has to be the most asked question here, or at least it's way up there with classpath and path questions.
    Use the search feature to search the forum for random number generation and I swear you'll find more answers and code than you could possibly want.
    Good luck
    Lee

  • Random numbers started appearing on lcd screen.

    I just started seeing random numbers appearing on my LCD Screen;  with that, the pictures also looked unclear.  Has anyone had this happen before?   Are there any fixes?  Thank you very much.  Happy Holidays!!
        Mark

    markpacana,
    Can you describe some of the numbers and where they appear on the LCD screen? (ex.  in one of the corners or on the sides)
    Do the numbers appear after every image that is taken?
    If this is a time sensitive-matter, additional support options are available at Contact Us.
    Did this answer your question? Please click the Accept as Solution button so that others may find the answer as well.

  • 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

  • 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);
    }          

  • I am trying to generate an array of 30 random numbers. after every 5 readings a new vi should open and tell the user that 5 readings has been completed. and again carry on with the generation of array.

    since i do not have a transducer now, i am currently generating an array of 30 random numbers. after every 5 readings a warning should be given to the user that 5 readngs are complete. this cycle should repeat. the array size is 30.
    please help me out,  waiting for reply asap.
    once i have the transducer, i will be taking 30 analog samples and then after every 5 smaples that wraning will be displaye din a new VI
    Solved!
    Go to Solution.

    Use a while loop with a time delay representing your sampling period.
    Use the count terminal to check if equals 4, so 4th iteration=5th sample.
    Use a case structure. The true case will only be executed on the 4th iteration.
    In the true case place a subVI  with your desired message in the front panel. Go to the VI properties window and set "open front panel when called".
    The closing condition of the warnign is not giving in your description.
    Consider that rather than usign a subvi for this, you could use the "One/Two/Three button dialog" or "display message" vis at the "dialog and user interface" pallete.
    Please give it a try and send your own VI. Do not expect us to provide a working solution.
    Regards,

  • 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.

  • I need help with this program ( Calculating Pi using random numbers)

    hi
    please understand that I am not trying to ask anymore to do this hw for me. I am new to java and working on the assignment. below is the specification of this program:
    Calculate PI using Random Numbers
    In geometry the ratio of the circumference of a circle to its diameter is known as �. The value of � can be estimated from an infinite series of the form:
    � / 4 = 1 - (1/3) + (1/5) - (1/7) + (1/9) - (1/11) + ...
    There is another novel approach to calculate �. Imagine that you have a dart board that is 2 units square. It inscribes a circle of unit radius. The center of the circle coincides with the center of the square. Now imagine that you throw darts at that dart board randomly. Then the ratio of the number of darts that fall within the circle to the total number of darts thrown is the same as the ratio of the area of the circle to the area of the square dart board. The area of a circle with unit radius is just � square unit. The area of the dart board is 4 square units. The ratio of the area of the circle to the area of the square is � / 4.
    To simuluate the throwing of darts we will use a random number generator. The Math class has a random() method that can be used. This method returns random numbers between 0.0 (inclusive) to 1.0 (exclusive). There is an even better random number generator that is provided the Random class. We will first create a Random object called randomGen. This random number generator needs a seed to get started. We will read the time from the System clock and use that as our seed.
    Random randomGen = new Random ( System.currentTimeMillis() );
    Imagine that the square dart board has a coordinate system attached to it. The upper right corner has coordinates ( 1.0, 1.0) and the lower left corner has coordinates ( -1.0, -1.0 ). It has sides that are 2 units long and its center (as well as the center of the inscribed circle) is at the origin.
    A random point inside the dart board can be specified by its x and y coordinates. These values are generated using the random number generator. There is a method nextDouble() that will return a double between 0.0 (inclusive) and 1.0 (exclusive). But we need random numbers between -1.0 and +1.0. The way we achieve that is:
    double xPos = (randomGen.nextDouble()) * 2 - 1.0;
    double yPos = (randomGen.nextDouble()) * 2 - 1.0;
    To determine if a point is inside the circle its distance from the center of the circle must be less than the radius of the circle. The distance of a point with coordinates ( xPos, yPos ) from the center is Math.sqrt ( xPos * xPos + yPos * yPos ). The radius of the circle is 1 unit.
    The class that you will be writing will be called CalculatePI. It will have the following structure:
    import java.util.*;
    public class CalculatePI
    public static boolean isInside ( double xPos, double yPos )
    public static double computePI ( int numThrows )
    public static void main ( String[] args )
    In your method main() you want to experiment and see if the accuracy of PI increases with the number of throws on the dartboard. You will compare your result with the value given by Math.PI. The quantity Difference in the output is your calculated value of PI minus Math.PI. Use the following number of throws to run your experiment - 100, 1000, 10,000, and 100,000. You will call the method computePI() with these numbers as input parameters. Your output will be of the following form:
    Computation of PI using Random Numbers
    Number of throws = 100, Computed PI = ..., Difference = ...
    Number of throws = 1000, Computed PI = ..., Difference = ...
    Number of throws = 10000, Computed PI = ..., Difference = ...
    Number of throws = 100000, Computed PI = ..., Difference = ...
    * Difference = Computed PI - Math.PI
    In the method computePI() you will simulate the throw of a dart by generating random numbers for the x and y coordinates. You will call the method isInside() to determine if the point is inside the circle or not. This you will do as many times as specified by the number of throws. You will keep a count of the number of times a dart landed inside the circle. That figure divided by the total number of throws is the ratio � / 4. The method computePI() will return the computed value of PI.
    and below is what i have so far:
    import java.util.*;
    public class CalculatePI
      public static boolean isInside ( double xPos, double yPos )
         double distance = Math.sqrt( xPos * xPos + yPos * yPos );        
      public static double computePI ( int numThrows )
        Random randomGen = new Random ( System.currentTimeMillis() );
        double xPos = (randomGen.nextDouble()) * 2 - 1.0;
        double yPos = (randomGen.nextDouble()) * 2 - 1.0;
        int hits = 0;
        int darts = 0;
        int i = 0;
        int areaSquare = 4 ;
        while (i <= numThrows)
            if (distance< 1)
                hits = hits + 1;
            if (distance <= areaSquare)
                darts = darts + 1;
            double PI = 4 * ( hits / darts );       
            i = i+1;
      public static void main ( String[] args )
        Scanner sc = new Scanner (System.in);
        System.out.print ("Enter number of throws:");
        int numThrows = sc.nextInt();
        double Difference = PI - Math.PI;
        System.out.println ("Number of throws = " + numThrows + ", Computed PI = " + PI + ", Difference = " + difference );       
    }when I tried to compile it says "cannot find variable 'distance' " in the while loop. but i thought i already declare that variable in the above method. Please give me some ideas to solve this problem and please check my program to see if there is any other mistakes.
    Thanks a lot.

    You've declared a local variable, distance, in the method isInside(). The scope of this variable is limited to the method in which it is declared. There is no declaration for distance in computePI() and that is why the compiler gives you an error.
    I won't check your entire program but I did notice that isInside() is declared to be a boolean method but doesn't return anything, let alone a boolean value. In fact, it doesn't even compute a boolean value.

  • Problem with Purchase Order creation with Random numbers .

    Hi Experts
    Currently i am facing an issue with Bapi BAPI_PO_CREATE1 to create Purchase order with random numbers for example items 1, 3,5.
    Please let me know the settings .
    Thanks in Advance

    Hi Neha,
    A reset of the release strategy only takes place if
    -  the changeability of the release indicator is set to '4' in
       case of a purchase requisition and '4' or '6' in case of
       another purchasing document (purchase order, request for
       quotation, contract, scheduling agreement),
    -  the document is still subject to the previous release
       strategy,
    -  the new TOTAL NET ORDER VALUE is higher than the old one.
    The total net order value is linked to CEKKO-GNETW for a purchase order,
    CEBAN-GSWRT for a purchase requisition item-wise release and CEBAN-GFWRT
    for a purchase requisition overall release.
    If you have maintained a Tolerance for value changes during release
    (V_161S-TLFAE), the release strategy is reset when the value of the
    document is higher than the percentage you have specified and if the
    document is still subject to the previous release strategy.
    Review the SAP note 365604 and 493900 for more
    information about Release strategy.
    Regards,
    Ashwini.

  • Program to create random numbers in plsql

    How do we Write a program to create random numbers.
    Thanks

    No need to - we have DBMS_RANDOM :)

  • Random letters to random numbers in the code template?

    I'd like to change the random letters of the code template in Motion 5 to be random numbers.
    PLATFORM: quad 2.9 macpro, Mavericks, 8 GB RAM, Motion 5.

    type the number you want. I highly recommend a monospace font (or at least a font with monospace number characters -- there are a few...)
    Add > Behaviors > Text Animation
    Parameter Add > Format > Character Offset
    Set Character Offset to 18 (seems to work well.)
    Character Set: Preserve Case & Digits
    Adjust Spread to taste.
    Consider Direction > Random

  • Random numbers in arrays

    i have been faced with a new problem, i have to generate a random number (between 0-63) of random numbers (between 0-63).
    Can i do this all in one array to randomly generate an array containing the random number of elementnts and set each of the elemnt to a random value.
    Random x = new Random();
    int j= x.nextInt(63);
    String [j] numbers;
    Random q = new Random();
    for(j=0, j<=numbers.length, j++)
       int f= q.nextInt(63);
      numbers[j] =f;
    } I had an idea of doing something like the code above can any see a better way to do it.

    I am getting this error
    java.lang.ArrayIndexOutOfBoundsException: 15
    from
    numbers[z] = rng.nextInt(63);i think this is because i am randomly calling the method, so it runs through it once but the second time it flags up the error.
    void Randm()
                         Random rng = new java.security.SecureRandom();
                    int o = rng.nextInt(63);//I hope you know this is zero to 63 exclusive, i.e., it can't return 63
                    int [] numbers = new int[o];
                    for(int z = 0 ; z <= numbers.length ; z++)
                        numbers[z] = rng.nextInt(63);// again, this will not return 63
                        System.out.println("ran gen "+numbers[z]);
    }I think it may be the way i am declaring the array, can anyone shed some light on the situation.

  • Random numbers in midp

    Am I missing something or is there no library method to generate random numbers in midp? if there isn't, can someone provide me with some link to a simple class that generates them or give some source.. I tried to use the date (time) to generate randoms but i need something more 'random'. And I'm sure there are many more tested and well working implementations etc. than I can come up with... :)

    import java.util.Random;
    import java.lang.Math;
    public class MyRandom
    { //Start of Class
         private Random random;
         //Constructor
         public MyRandom()
              random = new Random();     
         //Will return a number between 0 and maxint
         public int getInt(int maxint)
              return Math.abs(random.nextInt()>>>1) % (maxint + 1);
         //Will return a number between teh startint and the maxint
         public int getInt(int startint, int maxint)
              return startint + (Math.abs(random.nextInt()>>>1) % ((maxint-startint) + 1));     
    } //End of Class
    Hope this helps

  • Random numbers in Forte V 1.0

    Hi everyone,
    has anyone implemented a method to generate random numbers in Forte Release 1?
    Forte release 2 has just such a utility object, but would love some
    already written code if anyone has it.
    Thanks
    John
    John Jamison
    Engineering Manager
    Sage Solutions, Inc.
    415 392 7243 x 508
    [email protected]

    For everyone's info, there is one on the FSHARE CD that I contributed.
    It is called 'ransort' I believe. It will randomly generate as many
    random numbers as desired, and then provide another option to sort
    them. We no longer need the random generation part in V2, but the
    QuickSort routine is very fast, and worth taking a look at.
    Send me a note if you don't have access to FSHARE, and would prefer
    an export over the net.
    Lee Wei
    >
    Hi everyone,
    has anyone implemented a method to generate random numbers in Forte Release 1?
    Forte release 2 has just such a utility object, but would love some
    already written code if anyone has it.
    Thanks
    John
    John Jamison
    Engineering Manager
    Sage Solutions, Inc.
    415 392 7243 x 508
    [email protected]

Maybe you are looking for

  • Web report without userid and password

    Hi Experts, I exported a BW web report to excel spreadsheet and sent it through mail to others, When recepients tried to open that exported spreadsheet, It is prompting for userid and password. I dont want this to be happened and it should open witho

  • Issue with split of file

    Hello SAP Gurus, I have file to multiple idoc scenario , where i am not using any message mapping or FCC. However the file size is huge (60 MB) , so i want to divide the data and process it. So can i use the advanced mode of sender file adapter and u

  • Photo web gallery

    Is there any automated way to create a photo web gallery in fireworks or a third party plug in? I'm using Fireworks MX

  • Date format in ESS leave request

    Hi, The date format in ITS leave request is dd.mm.yyyy we have converted to webdynpro and now it has changed to mm.dd.yyyy. can somebody suggest how this can be changed to dd.mm.yyyy thanks n regards satya

  • Why can I STILL not send/receive MMS after trying every app, deleting, uninstalling, and resetting phone MULTIPLE times?

    I've tried absolutely EVERY POSSIBLE suggested fix and nothing.  I've had my phone since February, and it worked up until about 3 weeks ago.  My phone hasn't done any updates that I'm aware of, and I've checked manually for updates.  WHY???