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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:36:38+00:00 2026-06-16T20:36:38+00:00

Guys I’m getting this really weird fault with my program when I run it.

  • 0

Guys I’m getting this really weird fault with my program when I run it. This is the important code:

variables (edit):

const short int maxX = 100;
const short int maxZ = 100;
const short int lakeChance = 0.9;

addLake function (edit):

void addLake(Sect sector[][maxZ], int x, int z){    
    sector[x][z].setMaterial(1);
}

main source (edit):

//Generating land mass
for (int x = 0; x < maxX; x++){
    for (int z = 0; z < maxZ; z++){
        //Default material
        sector[x][z].setMaterial(0);

        //Add lake/sea source
        int r = rand();
        float r1 = (r % 1000);
        float r2 = r1 / 1000;

        if (r2 <= lakeChance) addLake(sector, x, z);
    }
}

The fault is, that whatever I change the ‘lakeChance’ value to, the result seems to be exactly the same. As in the addLake function seems to be called about 3 to 6 times every launch despite me changing the value of lakeChance higher (i.e.: 0.5, 0.7, 0.9). The function is only called all the time when I change the value of ‘lakeChance’ to 1. The random number generator works fine btw so the result are somewhat varying every time.

  • 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-16T20:36:39+00:00Added an answer on June 16, 2026 at 8:36 pm

    I see nothing obviously wrong per se. So I tried the following bit of code:

    int test(float chance)
    {
        int call = 0;
    
        for(int i = 0; i != 100000; i++)
        {
            int r = rand();
    
            float r1 = (r % 1000);
    
            float r2 = r1 / 1000;
    
            if(r2 <= chance)
                call++;
        }
    
        cout << "Chance is " << chance << ": " << call << " invocations or "
             << ((100.0 * call) / 100000.0) << "% of the time!" << endl;
    
        return call;    
    }
    

    Predictably, I got these results:

    Chance is 0.1: 10216 invocations or 10.216% of the time!
    Chance is 0.2: 20232 invocations or 20.232% of the time!
    Chance is 0.3: 30357 invocations or 30.357% of the time!
    Chance is 0.4: 40226 invocations or 40.226% of the time!
    Chance is 0.6: 60539 invocations or 60.539% of the time!
    Chance is 0.7: 70539 invocations or 70.539% of the time!
    Chance is 0.8: 80522 invocations or 80.522% of the time!
    Chance is 0.9: 90336 invocations or 90.336% of the time!
    Chance is 1: 100000 invocations or 100% of the time!
    

    How many lakes are you trying to add?

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

Sidebar

Related Questions

guys. I use XMLSerializer to keep and restore program options. Here is the code:
Guys i need some help here , im getting this error here at the
Guys this code is returning false in a blank page after submit.What is the
guys. I tried this code: def trap_check(payroll[][], timelive[][]) . . . end I was
guys, I would like to you evaluate next code below. As you see, I
Guys, I've came across this problem I can't resolve myselg, I'm pretty sure I
Guys I asked a similar question like this earlier since I was unable to
Guys, this can't be for real I'm trying to make a .NET 2.0 executable
Guys, I am very new to c++. I have just wrote this class: class
Guys, I have the following code that is inside a big while loop that

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.