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 7432569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:28:44+00:00 2026-05-29T09:28:44+00:00

I am working on a game. I want to do something like 50% of

  • 0

I am working on a game. I want to do something like 50% of the time it shows you are lucky today here is $100 and 50% of the time it should say better luck next time. Can anyone please guide me how can i do this? I am using eclipse and java.
I have this so far:

for (int a = 0; a < 100; a++) {
            int per = 0;
            per = GenerateRandom.getRandom(2);
                        if (per<50)
                        {"better luck next time"}
                        else
                        {"you won $100"}
}

Is this right way to do? Or is there better way to do it?

  • 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-05-29T09:28:45+00:00Added an answer on May 29, 2026 at 9:28 am

    First – no, that’s not quite the way to do it. You would want to make use of the Random class in Android to generate pseudo-random numbers. (You can learn more about PRNGs here.)

    In my mind, the best way to do this (from a practical Java standpoint is to use code similar to the following:

    public String isLucky() {
        Random ran = new Random() * 100; // Generates values between 0 and 100 exclusive
        return ran <= 49 ? "Better luck next time!" : "You win $100!"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on a game in c# that I want to put
I'm currently working on a game in Java and I want to calculate the
I am working on an android game. I want to copy a text file
I am working on game. I want to highlight a spot on the screen
I'm working on a game and want the freedom to choose between UDP and
Working on a game project that involves a scripting language that I want to
I am working on a client/server game (C#.NET) where I do not want to
I'm working on a tower defense game and I want the defending turrets to
Working on game where plates will be falling from top to bottom. Some plates
I am working on game application and i use AnimationDrawable for image change. but

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.