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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:55:21+00:00 2026-05-21T03:55:21+00:00

I am currently coding a roguelike, and naturally am using a lot of random

  • 0

I am currently coding a roguelike, and naturally am using a lot of random number generation.

The problem I’m running up on is that if I “overheat” rand(); my program will crash.

If i’m only generating 20 or so ints per frame, it’s fine… but when the amount of random numbers goes into the hundreds, the program crashes. The more I’m producing every frame, the sooner it crashes… which leads me to believe there is some pileup going on.

I’ve done tests, and at 20 rand(); calls per frame, it will run for 24 hours straight at max speed without crashing. Triple that and it doesn’t make it ten minutes.

If I put srand(); in the initialization, i can churn out thousands of random numbers before it locks up – but if I put srand(); within the frame itself, i make it about 2-8 frames. If it matters, I’m using time(null) to seed.

the more frequently i call rand(); the sooner it crashes.

Help?

  • 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-21T03:55:22+00:00Added an answer on May 21, 2026 at 3:55 am

    A few comments and ideas on how to narrow down the source of the issue:

    • It almost certainly is not the srand() or rand() functions causing the crash/lock up. Chances are that one, or more, combinations of random numbers is getting your engine into a state where something bad happens.
    • The first step should be to duplicate the issue such that it always happens at the time/place. Instead of using a srand(NULL) try using a constant seed like srand(12345). Depending on what other factors your engine uses (like user input) this may be enough to get it to crash in the same spot each time.
    • If using the debugger is having issues (which is suspect, perhaps a buffer overflow is corrupting the stack) use the tried and true method of outputting messages to a text log file. I would suggest outputting all the random numbers generated and perhaps you may see a pattern on when it crashes (i.e, it crashes whenever a “42” is generated). Another option is to start adding a few log message in various functions (start with high level functions like your game update loop). After a crash check the log and begin adding more log messages until you narrow it down to one line/function. This is not as quick as using the debugger can be but is sometimes a better choice, especially if you don’t really know where to start looking.
    • Once you are able to reliably replicate the crash start removing things until the crash point changes or disappears. This may involve #ifdefs, commenting out code, setting application options, or even creating a temporary copy of the project so you can simply delete code, compile, and test. This may be difficult if the project is large/complex.
    • More information on the type of “crash” would be helpful. Usually programs don’t just crash generically but have a certain exception occur, lock-up, etc…. Exception details can help you narrow down the source of the issue with some effort.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently coding a HTML website into wordpress. The problem that i'm having
I am currently coding a C# application that displays a image using PictureBox on
I am currently coding some chat program and now want to play music via
I'm currently coding counter system and have spotted one problem with flash banners without
I'm currently coding an app that has hotkey functionality, I've done some reading and
I am currently coding a Java WebService using axis2. However, one particular request needs
I am currently coding an application that involves navigating between pivot control. There will
I'm currently coding a simple search script in PHP that requires three variables from
Having a slight c# problem here. I'm currently coding a small platformer-game with Unity
I am currently coding a web page that allows users to change local settings

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.