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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:41:31+00:00 2026-06-09T05:41:31+00:00

I have the following code. Random r works and gets me about 10% into

  • 0

I have the following code. Random r works and gets me about 10% into the if. However rr doesn’t seem to work. It always returns 0. What am I doing wrong?

I want to choose between two choices randomly only 10% of the time. This is in an asp.net app. The code gets executed on button click.

        Random r = new Random();
        Random rr = new Random();

        int randomnum = r.Next(0, 100);
        if (randomnum <= 10)
        {

            int randompick = rr.Next(0, 2);
            if (randompick == 0)
            {
  • 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-09T05:41:32+00:00Added an answer on June 9, 2026 at 5:41 am

    If you are happy with the outer loop’s randomness, consider

    int randompick = randomnum % 2;
    

    instead of the nested Random object.

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

Sidebar

Related Questions

I have the following code: from random import randint,choice add=lambda x:lambda y:x+y sub=lambda x:lambda
I have the following code: import string import random d =[random.choice(string.uppercase) for x in
I have the following code to generate two random numbers var attackRoll = Math.floor((Math.random()*6)+1);
I have the following line of code in javascript: (Math.random() + ) * 1000000000000000000
I have following code for inserting data into database using PDO. It inserts data
I have the following javascript code, which is doing an image rotation on a
I have the following test code to encrypt and decrypt a string. It works
I want to clarify how the following code works.I have itemized my doubts to
I have the following code which works and gives me each value. I can't
So I have the following code, and It works nearly flawlessly, except for the

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.