Generating random numbers, while excluding some numbers

I want to generate random numbers between 1 and 13 (including 1 and 13), while excluding numbers 6 and 9
Please tell me theres an easy fix to this issue --

lemme know if it compiles
import java.util.*;
public class RandomNumber {
public static void main( String[] args) {
int numWins = 0;
for( int i = 1; i < 101; i++) {
boolean x = true, y = true;
int number = 0;
while(!x && !y && number != 6 && number != 9)
number = 1 + (int) (Math.random() % 13);
x = number >= 1;
y = number <= 13;
int number2 = 0;
while(!x && !y && number2 != 6 && number2 != 9)
number2 = 1 + (int) (Math.random() % 13);
x = number2 >= 1;
y = number2 <= 13;
int number3 = 0;
while(!x && !y && number3 != 6 && number3 != 9)
number3 = 1 + (int) (Math.random() % 13);
x = number3 >= 1;
y = number3 <= 13;
int number4 = 0;
while(!x && !y && number4 != 6 && number4 != 9)
number4 = 1 + (int) (Math.random() % 13);
x = number4 >= 1;
y = number4 <= 13;
int DrawAgain = 2;
if (number == DrawAgain) {
System.out.println( "A Random number between 1 and 10: " + number);
System.out.println( "A second Random number between 1 and 10: " + number2);
if (number2 == 8) {
System.out.println( " Piece made it home successfully");
numWins++;
if (number2 == DrawAgain) {
System.out.println( "A third Random number between 1 and 10: " + number3);
if (number2 == 7) {
System.out.println( " Piece made it home successfully");
numWins++;
if (number3 == DrawAgain) {
if (number4 == 7)
System.out.println( " Piece made it home successfully");
numWins++;
else {
System.out.println( "A Random number between 1 and 10: " + number);
if (number == 10) {
System.out.println( " Piece made it home successfully");
numWins++;
System.out.println(" Number of times piece made it home successfully " + numWins);
}

Similar Messages

  • How to generate random numbers that doesnt contain characters?

    How do we generate random numbers in ESB ROuting Service/ XSL transformation that does not contain characters. I have been using "orcl:generate-guid()" , but it contains some characters, so, I substring it to get only numbers. I dont want to take this risk and in future, my substring itself may contain characters.
    Has anybdy tried this before?
    Thanks,

    If the goal is to have a pseudo random number then consider using the translate function to replace the occurances of the A - E characters with another digit. For example:
    translate(orcl:generate-guid(),'0123456789ABCDEF','0123456789123456')
    This will produce a 1 for A, 2 for B, etc. While not a valid hex to decimal conversion of the GUID value, it does get around the hex issue and might be sufficient for your purposes.
    I would perform a large sample test to see just how unique the values end up being.
    As for why hex is used, well GUID's are most commonly written in text as a sequence of hexadecimal digits such as: 3F2504E0-4F89-11D3-9A0C-0305E82C3301. i.e. 128 bits represented in 32 characters formatted into 5 sections.
    Hope this helps,
    Peter

  • Need An Algorithm That Generates Random Numbers

    Hi, I understand that there is a built-in random number generator. But, I need an algorithm that generator random numbers. Is there one available? Thanks.

    Hi, is the "Seminumerical Algorithms" a book?What
    the numbers 3141592621 and 907633385 stand for?The first is PI without a decimal... the second I
    don't know, it may as well be randomly picked.As far as I know the numbers aren't randomly picked. You want the distribution to be good, and the length of the serie should also be long. Some numbers causes the cycle to be short, or the distribution to be bad. I think there are articles that lists 'good' numbers.
    /Kaj

  • Please help to write a java code for generate Random numbers

    I need a program for generate Random integer numbers by using roulette wheel theory. I search several ares, but I'm unable to find out at lease a Pseudo code for implement this. If you know or have a code for this, Please send me a mail to [email protected] or post here.

    Gagana wrote:
    I need a program for generate Random integer numbers Have a look at the java.util.Random class:
    [http://java.sun.com/j2se/1.5.0/docs/api/java/util/Random.html]
    Or Google:
    [http://www.google.com/search?q=random+java]
    by using roulette wheel theory. What is that?
    ... Please send me a mail to [email protected]
    No, that defeats the purpose of a public forum. And no one is going to e-mail you (other than someone trying to sell V1AGRA).

  • How do I generate random numbers from a list of numbers without repeating any number

    I am trying to generate a list of random numbers without any repeating numbers.  For example say the list is from 1 to 15, how do I randomly generate a list of numbers using each number only once?

    pb,
    You can build a randomizer by making a 2-column table with 15 rows. In Column A, Fill with the numbers 1 to 15. In column B Fill with RAND(). Then sort on Column B. There will now be a randomized list of the numbers from 1 to 15 in Column A. You can copy this random list and use it in your application.
    Jerry

  • How to generate random numbers from 1 to 5

    How to generate random numbers from 1 to 5   
    -1110340081
    Solved!
    Go to Solution.

    (You should not mark a post as solution unless it actually contains a solution to the original problem)
    Do you want to share your code? Did you test to make sure that all numbers equally probable?
    LabVIEW Champion . Do more with less code and in less time .

  • How to generate random numbers in a range using random class?

    I know how to use Math.random for this, but how would I generate random numbers using the random class?
    Say I want a number between 40 and 50, inclusive--how would I do this?
    What i have in mind is:
    int randomNumber = random.nextInt(max) + min;
    where max is 50 and min is 40. Is this correct?

    Fredddir_Java wrote:
    I know how to use Math.random for this, but how would I generate random numbers using the random class?
    Say I want a number between 40 and 50, inclusive--how would I do this?
    What i have in mind is:
    int randomNumber = random.nextInt(max) + min;
    where max is 50 and min is 40. Is this correct?What happened when you generated a couple hundred numbers that way? Did you get all the ints in the range you wanted?

  • Exclude some pages from page numbering

    Hey,
    I create an RTF template to produce PDF output.
    I want to exclude some pages from the page numbering.
    Does someone know how this may be possible?
    Thanks for your assistance
    brgds,
    David DC

    I think I was "nearly" able to achieve what you want to achieve.
    I used Word 2003 - just in case and 5.6.x (hope it doesn't matter).
    You need to create two section breaks:
    Page 1
    --- Section Break ---
    Page2 - No page numbering
    --- Section Break
    Page 3- (which will show page number 2).
    For the first page you can pretty much hard code the page number.
    For the second page you go to the header and
    1) Select "unlink to previous" from the header/footer toolbar
    2) Remove the page numbering from the second page.
    For the third page (section 3) you go to the header and:
    1) Select "unlink to previous" from the header/footer toolbar
    2) Remove the previous header
    3) Insert the page number, select it with the cursor
    then select "Format Page Number" from the header/footer toolbar.
    4) In this dialog box you select under page numbering "start at": 2
    5) Insert the total number of pages, select the field with the cursor
    then select "Format Page Number" from the header/footer toolbar.
    6) In this dialog box you select under page numbering "start at": 2
    FUNNY - in Word it still stays Page 2 of 3 in the header of the third page, but
    when I run it with XML Publisher I get Page 2 of 2.
    So I get after the run for the page header of a 3 page document:
    Page 1 Header:
    Page 1 - NO PAGE TOTAL - I get to this later
    Page 2 Header:
    NO PAGE HEADER
    Page 3 Header:
    Page 2 of 2
    Now how do I get the correct page number onto the first page - I tried a trick and it worked...
    1) Insert a bookmark (ie. name test) behind the last word of your document - on the last page. Menu: Insert bookmark
    2) Go to the header of the header of the first page behind:
    Page 1 of
    3) Now select from the menu Insert: Referernce -> Cross reference.
    4) Select refernce type "Bookmark" ,
    Insert refence to "Page Number"
    Select reference to test.
    Worked for me... Let me know if that is what you wanted to achieve and if it works for you.
    Klaus

  • InfoPath library generates random ID numbers

    I have created an infopath lib.
    Sometimes when submitting a form sharepoints is skipping 100 (aprox)  ID's and generates random ID number...
    Can anyone help what might be the reason for that?
    Thx, Ofer

    I am suspecting this...
    My clients asked me to show the form ID after save.
    So, here is my solution:
    I do submit on the 1st time & then query my lib with the form name (which I know) &
    resubmit again to save the ID + additional nested data.
    (The implementation is quite complicated & in some cases I must resubmit after the 1st time...)
    I've noticed that in the most of these cases SP skips 99 ID's

  • Why do some questions on these forums begin with HT or TS and some numbers?

    This is a random question that I've been curious about for a while.  Some of the questions' titles on these forums begin with the letters HT and end in random numbers.  Some also begin with TS... What does this mean?

    I'm sorry, Allan, but those are always preseeded by the Apple symbol as in

  • Can you skip numbers while using pages?

    I am working on a syllabus for class and we are asked to skip some questions. Is there a way to skip numbers while in pages? Example being
    1.
    2.
    3.
    5.
    6.
    8.
    I'm having a hard time trying to figure it out.
    Thanks

    Screen shots are taken by pressing the COMMAND-SHIFT keys and then '3'.
    Ciao.

  • Can't connect to some numbers on iPhone 4s after updating to iOS 8

    Since updating to iOS 8, I can successfully call some numbers, but for some I  get a message such as "Welcome to Verizon Wireless. Your call cannot be completed as dialed. Please check the number and dial again."  There's also a mention of "switch 18-2". But I can make the call from a landline. Any fixes?

    Try a reset of network settings. To do so, tap on Settings > General > Reset > Reset Network Settings. This will not delete your personal data.

  • I'm having a problem sending photos to some numbers via messages.

    I'm having problems sending pictures via messages. Some numbers (where the people have IPhones ) they go though where others as soon as I hit send they comeback Not delivered. Help?

    You may be transmitting to Apple users using iMessage.  But to transmit to non-Apple users, you must rely on your cellular carrier's MMS.
    First, you must have Settings > Messages > MMS Messaging set "On".  Second, you must have an MMS arrangement with your cellular carrier.

  • TS1292 The itune car I have has a bar code and numbers underneath, however some of the numbers are missing is there anyway I can use this card

    The itune card I have has a bar code and numbers underneath, however some of the numbers are missing is there anyway I can use this card?

    Hi,
    Here is a Support Article that will help:
    http://support.apple.com/kb/HT6021
    Cheers,
    GB

  • Print out some numbers

    Hello:
    At the movement I got array nums[]={"1", "2", "3", "4", "5", "6", "7", "8"},
    Please tell me how to print out some numbers from the array by using for loop, and the result exactly like System.out.println( " 1 2 3 4 "); System.out.println(" 5 6 7 8);
    Please run my codeing first, I'd like the result exactly same as my coding showing.
    Thanks
    import java.awt.*;
    public class Test{
    private static Test t;
    private static String nums[]={"1", "2", "3", "4", "5", "6", "7","8"};
    public static void main(String [] args){
         t=new Test();
    private Test(){
         print();
    private void print(){
         System.out.println(" 1 2 3 4 ");
         System.out.println(" 5 6 7 8 ");
    }

    Ugh!
    I didn't see that you wanted 1,2,3,4 and 5,6,7,8 on new lines. This will do the trick. It's ugly but it works.
    public class Test
        private static Test t;
        private static String nums[] = {"1", "2", "3", "4", "5", "6", "7", "8"};
        public static void main( String[] args )
            new Test();
        private Test()
            print();
        private void print()
            for (int i = 0; i < nums.length; i++) {
                if (i == 4) {
                    // Print a Blank Line
                    System.out.println("");
                String num = nums;
    System.out.print(num + " ");
    cheers,
    Greg

Maybe you are looking for

  • Activex server excel example in LV 8.0

    Does anybody know how to get the following ActiveX Server example working for LV 8? labview\examples\comm\freqresp.xls  The menu items appear to have been moved.  The equivalent (VI Server) options under Tools-->Options don't appear to work. Has anyb

  • Need of a self explanatory method like toString(): Your Opinion?

    Hi All, If including a method like showHelp() is recommended as java programming standard like incorporating toString() in a class, it will serve as an online help mechanism for developers using the class. It will be helpful reference when the source

  • Skype pops up, how do i stop it?

    Skype pops up. How do i stop it?

  • Adding Notes In Purchase order

    Hi Gurus, 1.How to add Note to Supplier of data of A4 Size Paper in Purchase Order Other Than Attachment 2.If It IS Attachment How To Integrate it with the Po Print Out 3.This Note Must Be General And Should be Printed in All Po Standard Foramt How t

  • Can substitution strings be changed at runtime?

    I need to deploy my application such that it can run with different sets of tables, which are otherwise identical in design. My client has multiple versions of the tables. For instance, they may have CHICAGO.EMPLOYEES CHICAGO.DEPARTMENTS or LONDON.EM