Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8932785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:23:15+00:00 2026-06-15T09:23:15+00:00

that is the exact code then i have a switch for case 0: and

  • 0

that is the exact code then i have a switch for case 0: and case 1: it seems that the case 1: is coming out every time, i would like to have a 50/50 chance of 0 or 1 coming out is this the correct way or should i use 1.5 or how exactly does this work?

talka = (int)(Math.random() * 1);
        switch(talka)
        {

        case 0:
        {
            talk.setAnimationListener(this);
            talk.playtimes(1,24);
            startService(new Intent(this, love1.class));
            break;
        }
        case 1:
        {
            talk.setAnimationListener(this);
            talk.playtimes(1,12);
            startService(new Intent(this, love2.class));
            break;
        }
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:23:17+00:00Added an answer on June 15, 2026 at 9:23 am

    The problem has to do with the way the cast works.

    In may test, Java was basically “trimming” the decimal result off and simply taking the “integer” component. However, if I rounded the result, I got it flipping between 0 and 1.

    Have a play

    int ones = 0;
    int zeros = 0;
    for (int index = 0; index < 100; index++) {
    
        double rand = Math.random() * 1;
        if (Math.round(rand) == 1) {
            ones++;
        } else {
            zeros++;
        }
        System.out.println(rand + " - " + (int)Math.round(rand) + " - " + (int)Math.random() * 1);
    
    }
    
    System.out.println("Ones = " + ((float)ones / 100f));
    System.out.println("Zeros = " + ((float)zeros / 100f));
    

    It my simple test, I was getting around the 50/50 mark (+/-)

    As pointed out by Hovercraft, better to use java.util.Random in this case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that takes the exact same args, but sometimes I'd like
All- I have a ton of Spinners that I would like to store in
I have 2 classes that have exact two functions. The difference between them is
I have a lot of web pages that use the same exact html structure.
I am wanting to have the EXACT same data across two WordPress sites that
I have a bit of code for a dll that is needed by two
I have two files that are exact in coding, file A and B. Within
Ok, so I have a form that takes a username and a code. This
I have a trigger that is firing with out issue in non-production but the
I have a JavaScript slideshow that pre-loads images out of a MySQL database and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.