Random numbers to make simple bingo game

Hi folks.
I am making a simple Bingo game in Director.
1. generate a random number up to 75; Number=random(75)
2. check if this number is on a list
3. if not the number is valid and code executed to display
the "bingo ball"
4. add the number to the list
and repeat.
Is this valid? Are there problems with this approach, ie. as
the numbers are called, the random number generated has more
likelihood of being on the list already so will speed take a hit?
OR is there another way to do this?
Thanks in advance

The issue with your approach will be evident when you've
removed a bunch of numbers already. What you will see is that the
number of times you will have to repeat step 2 will grow each time
you draw a bing ball as the number of balls drawn increases. How I
would approach it is in the reverse...
1. create your list of numbers from 1 to 75, procedurally at
the beginning:
bingoList = []
repeat witih j = 1 to 75
bingoList.add(j)
end repeat
-- that gives us a list containing the numbers from 1 to 75.
2. Now, all you have to do is generate a random number based
off the number of items in the list and then remove that item from
the list:
listCount = bingoList.count
bingoBallPosition = random(listCount)
-- get the bingo ball value at the position in the list:
bingoBall = bingoList[bingoBallPosition]
-- remove that ball number from the list
bingoList.deleteAt(bingoBallPosition)
You will have to do other things such as setting the
bingoList as a global or property variable depending on how you
code your project....
you may want to se this up in a moviescript if you're a
novice programmer so you can call the handlers from anywhere in
your project... so you'd probably want to create a newGame handler
that would set up your list (and other stuff)....
-- moviescript
global bingoList, bingoBall
on newGame
bingoList = []
repeat witih j = 1 to 75
bingoList.add(j)
end repeat
end newGame
on getBingoBall
listCount = bingoList.count
bingoBallPosition = random(listCount)
-- get the bingo ball value at the position in the list:
bingoBall = bingoList[bingoBallPosition]
-- remove that ball number from the list
bingoList.deleteAt(bingoBall)
-- do other stuff here such as display the bingo ball
end getBingoBall

Similar Messages

  • Where can I buy the code or buy the book to make a simple flash game?

    I need to make or buy a template for a simple flash game for a clients website. It has to be legit to buy. It is about 5 pages long. You are asked a question, you select a radio button for the answer to the question, it compiles all your answers and gives you a result.
    I know flash pretty well but ccording to budget and time.it is best not to have to experiment.
    Let me know, I appreciate the imput!

    http://activeden.net/searches?term=quiz&type=files

  • Random numbers for my game

    How, can I get a random number from 1 to 2, like 50% chances.
    Im making a racing game, and I need the computer to flip a coin
    (randomly draw a number) and if its 1 go slower, if 2 go faster.
    I cant get the random numbers to work. Can anyone show me the simplest way to do this?
    thanks

    there are loads of ways of doing it :P
    However, these are the 3 best. (you'd have to benchmark, 2 see which was fastest)
    though, i'd wager random1or2a is the faster.
    static Random random = new Random();
    // method 1
    public int random1or2a()
    return random.nextBoolean()?1:2;
    // method 2
    public int random1or2b()
    return (random.nextInt()&1)+1;
    }and method 3...
    class BetterRandom extends Random
       public int next(int n)
          return super.next(n);
    static BetterRandom random = new BetterRandom()
    public int random1or2c()
    return random.next(1)+1;
    }abu,
    p.s. I still don't understand why 'int next(int n)' has protected access. IMHO, it should be public.

  • 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

  • Array of unique random numbers - help?

    basically, i'm trying to create a BINGO card.
    i stared learning Java a week ago and am finding it easy to learn and use....at least so far.
    my instructor gave me the assignment to created a BINGO card. so i used the system.out.format command to make 5 tab fields, 8 spaces each ("%8s %8s %8s %8s %8s", "B", "I", "N", "G", "O"). although the assignment only wanted me to think numbers out of thin air, just to use as examples, i went above and beyond with the idea to make a BINGO card generator that could actually function.
    then i started the random number sequences, using the Math.random() command. all told, there are 24 of these in the program, one for each number on a bingo card. the field in the middle is the FREE space, so it has no Math.random command.
    in BINGO, each letter (one of my five tab fields) can have a number in ranges of 15. B is 1 to 15, I is 16 to 30, etc. it looks similar to this:
    B I N G O
    9 19 39 57 66
    3 28 32 51 74
    3 29 FREE 46 70
    14 28 43 55 67
    9 24 35 59 62
    as you can tell, i'm having trouble with actually making unique random numbers so that none repeat.
    is there a command or string or something to help me accomplish this?

    The best way I've come up with is to use an object to store the numbers that implements Collection--like ArrayList...
    Then you load it with the range of numbers that you want and call, shuffle() on the object, that will randomize your range of numbers and then you can choose the quantity you want from the storage object. So let's say you need 25 number in the range of 1 to 100:
    Add the numbers (you have to use classes so I would do Integers) 1 to 100;
    call shuffle()
    pull back the first 25 numbers
    This will guarantee that each number is distinct and in a random order.
    If you need multiple sheets populated, you can just call shuffle() between population of each sheet.
    package Junk;
    import java.util.ArrayList;
    import java.util.Collections;
    class Junk{
      private ArrayList<Integer> l;
      Junk(){
        l = new ArrayList<Integer>();
      public void loadList(int s, int e){
        for(int i=s; i<=e; i++){
          l.add(new Integer(i));
      public void randomizeList(){
        Collections.shuffle(l);
      public void printList5(){
        for(int i=0; i<5; i++){
          System.out.println(l.get(i));
      public static void main(String[] args){
        Junk j = new Junk();
        j.loadList(10,99);
        j.randomizeList();
        j.printList5();
        System.out.println();
        j.randomizeList();
        j.printList5();
    }

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

  • Need help with a simple basketball game.

    Hi im new here and I need help with making this simple basketball game.
    Im trying to recreate this game from this video. Im not sure if he is using as2 or as3
    Or if anyone could help me make a game like this or direct me to a link on how to do it It would be greatly appreciated.

    If you couldn't tell whether it is AS2 or AS3, it is doubtful you can turn it from AS2 into AS3, at least not until you learn both languages.  There is no tool made that does it for you.

  • 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

  • How to get the desired total of Random numbers ?

    I m in a big problem and want a urgent solution.
    I want to randomise numbers with specified limit and the total of all the randomised numbers should be desirable.
    e.g. if i m generating random number 24 times in a loop then the total of all the gerenrated numbers should be 100 and each randomised generated number should not be greater than 6.
    Please help me out. is there any method from which i can get, desirable total from the gererated random numbers ?
    Please help.
    thanks in advance

    In my usual manner, I'll throw in a couple of ideas and leave others to discard them again :-)
    Pick random numbers. If, at some point, the sum goes over 100, throw away the last number at instead put in the number that will make the sum exactly 100. Then put in 0 until you have 24 numbers. Those 0s won't look random. If it helps, shuffle all the numbers so the 0 come in random places in the sequence. If it's still not random enough, discard the whole idea. If, on the other hand, you still are m numbers short of 24 numbers and the sum goes under 100 - (m * 6), in a similar manner stop using randomness and throw in the numbers needed to hit 100. Shuffle to distribute the 6s.
    Another idea, there are 100 ^ 24 or 10 ^ 48 ways to put 100 balls into 24 buckets. Find out how many ways there are under the constraint that you can put at most 6 balls into a bucket. Enumerate them, pick one at random and generate it. I would say that this should give you a good randomness, but does it also look that way under your requirements?

  • How to fill an array with random numbers

    Can anybody tell me how I can fill an array with thousand random numbers between 0 and 10000?

    import java.util.Random;
    class random
         static int[] bull(int size) {
              int[] numbers = new int[size];
              Random select = new Random();
              for(int i=0;i<numbers.length;i++) {
    harris:
    for(;;) {
    int trelos=select.nextInt(10000);
    numbers=trelos;
                        for(int j=0;j<i;j++) {
    if(trelos==numbers[j])
    continue harris;
    numbers[i]=trelos;
    break;
    return numbers;
    /*This method fills an array with numbers and there is no possibility two numbers to be the
         same*/
    /*The following method is a simpler method,but it is possible two numbers to be the same*/
    static int[] bull2(int size) {
         int[] numbers = new int[size];
    Random select = new Random();
    for(int i=0;i<numbers.length;i++)
              numbers[i]=select.nextInt(9);
              return numbers;
         public static void main(String[] args) {
    int[] nikos = random.bull(10);
    int[] nikos2 = random.bull2(10);
    for(int i=0;i<nikos.length;i++)
    System.out.println(nikos[i]);
    for(int i=0;i<nikos2.length;i++)
    System.out.println(nikos2[i]);

  • Division of random numbers, see if the result is an integer.

    Simple and yet cant find an easy way around it.
    I have 2 RANDOM numbers coming in, I'm dividing them and I want to see if the result is an integer or not. Basically I need to see if the divison of the 2 random numbers provides a whole number.
    Who wants KUDOS?
    /spaw
    Solved!
    Go to Solution.

    Use Quotient and Remainder, check if Remainder is 0.

  • 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];

  • Random Numbers with Objective-C

    Hey Guys,
    I'm creating a blackjack program and I need to randomize 52 numbers, ensuring not to repeat any number.
    I know I can use the following to generate a number between 1-52, but I need the to eliminate the possibility of the same card being drawn twice:
    cardNumber = arc4random() % 52 + 1;
    Any idea on how I would do this? Code example would be helpful!
    Thanks,
    Justin

    Hi Justin -
    Justin Carman wrote:
    I'm creating a blackjack program and I need to randomize 52 numbers, ensuring not to repeat any number.
    I would initialize an array (the deck) with the card values, then use your random number as the index into the array. Each time a card is chosen just remove its value from the deck and decrement the modulus of the random numbers. NSMutableArray makes a nice deck for this purpose since its count is automatically decremented each time a value is removed. E.g.:
    // AppController.m
    #import "AppController.h"
    #define N_DECK 52
    @implementation AppController
    @synthesize cardArray; // @property (nonatomic, retain) NSMutableArray *cardArray;
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    self.cardArray = [NSMutableArray arrayWithCapacity:N_DECK];
    - (IBAction)newDeck:(id)sender {
    [cardArray removeAllObjects];
    for (int i = 0; i < N_DECK; i++) {
    [cardArray addObject:[NSNumber numberWithInt:i+1]];
    // NSLog(@"newDeck: cardArray=%@", cardArray);
    - (IBAction)getCard:(id)sender {
    // check the array
    int count = [cardArray count];
    assert(count <= N_DECK);
    if (count < 1) {
    NSLog(@"getCard: Empty deck");
    return;
    NSLog(@"getCard: count=%d", count);
    // select a card from the array
    int index = arc4random() % count;
    NSNumber *selected = [cardArray objectAtIndex:index];
    NSLog(@"getCard: index=%d selected=%@", index, selected);
    // print the value of the selected card
    int card = [selected intValue];
    NSLog(@"getCard: card=%d", card);
    // remove the selected card from the array
    [cardArray removeObjectAtIndex:index];
    // note selected NSNumber object has been released
    // NSLog(@"getCard: cardArray=%@", cardArray);
    @end
    For extra credit you might want to wrap the above in a custom Deck class.
    Hope that helps!
    - Ray

  • 6 random numbers without repeat

    I'm trying to make a 6 digit random number generator between 1 and 48. When the user click a button 6 random numbers show up in 6 different textFeilds. The problem is that I don't want the same number twice. How can I generate 6 different random numbers without using return and breaking out of the function?
    import flash.events.Event;
    stop();
    btn.addEventListener (MouseEvent.CLICK, random1);
    function random1 (evt:Event) {
              display1.text = "";
              display2.text = "";
              display3.text = "";
              display4.text = "";
              display5.text = "";
              display6.text = "";
              var r1 = Math.floor(Math.random()*(1+48-1))+1;
              var r2 = Math.floor(Math.random()*(1+48-1))+1;
              var r3 = Math.floor(Math.random()*(1+48-1))+1;
              var r4 = Math.floor(Math.random()*(1+48-1))+1;
              var r5 = Math.floor(Math.random()*(1+48-1))+1;
              var r6 = Math.floor(Math.random()*(1+48-1))+1;
              if (r2 == r1 || r3 == r2 || r4 == r3 || r5 == r4 || r6 == r5) {
                        return;
              var liste:Array = new Array();
              liste.push(r1,r2,r3,r4,r5,r6);
              liste.sort(Array.NUMERIC);
              display1.text = String(liste[0]);
              display2.text = String(liste[1]);
              display3.text = String(liste[2]);
              display4.text = String(liste[3]);
              display5.text = String(liste[4]);
              display6.text = String(liste[5]);

    Here's the code for the approach mentioned with your textfields included
    btn.addEventListener (MouseEvent.CLICK, random1);
    function random1 (evt:Event) {
        var nums:Array = new Array();
        // fill the array of numbers
        for(var i:uint=1; i<=48; i++){
            nums.push(i);
        shuffle(nums);
        // grab the first six in the shuffled array
        var liste:Array = nums.splice(0,6);
        // assign the values to the textfields
        for(var j:uint=1; j<=6; j++){
            this["display"+String(j)].text = String(liste[j]);
    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;

  • 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?
    }

Maybe you are looking for

  • How do I remove a song from an album without removing it from my computer library or another album?

    How do I remove a song from an itunes album on my MacBook without removing it from my library or from another album. It ended up in the wrong album

  • Hp LaserJet Printer 1300 Installation Problem

    I have Hp Laser Jet 1300 Printer want to plug it with Dell an Thosiba laptop. I have orignal drivers cd with it but, During Installation, its stop and gives error that Unable to install Printer.

  • Audigy 2 in Vista just stops working

    I have a problem with my Audigy 2 in Vista64. The card works fine in all applications, but at times the sound just stops, and I have to switch to the SPDIF Out as my playback device until I reboot. I tried to uninstall and reinstall drivers but the p

  • Set User Profile Picture with CMD

    Can we set the an user profile picture from a shared folder (\\SERVER\UserPictures\%USERNAME%.jpg) via CMD? How to do that? Thanks in advance.

  • Migration from PC to Mac

    Hi - I'm a brand new Mac user (so excuse my ignorance!)... I migrated my PC data using the Mac "migration" tool (after the mac setup process when using for the first time), but this has now created a new user login profile, and therefore all the migr