Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update RNG to use Borland C++ RNG Routine #579

Merged
merged 4 commits into from
Jul 15, 2023
Merged

Update RNG to use Borland C++ RNG Routine #579

merged 4 commits into from
Jul 15, 2023

Conversation

enusbaum
Copy link
Member

@enusbaum enusbaum commented Jul 9, 2023

  • Update srand() to set seed in memory
  • Change rand() from using internal C# RNG to ported Borland C++ routine

- Update `srand()` to set seed in memory
- Change `rand()` from using internal C# RNG to ported Borland C++ routine
@enusbaum enusbaum requested a review from paladine July 9, 2023 20:11
@enusbaum
Copy link
Member Author

enusbaum commented Jul 9, 2023

Verified against Borland C++ 4.5

Compiled the following using bcc rand.cpp:

#include <stdlib.h>
#include <stdio.h>
#include <time.h>

int main() {
    // Seed the random number generator
    srand(1234);

    // Generate and output the next three random numbers
    for (int i = 0; i < 10; ++i) {
        int randomNum = rand();
        printf("Random number %d: %d\n", (i + 1), randomNum);
    }

    return 0;
}

Output Results:

image

Unit Tests for rand() are verified against this list

- Enhanced Unit Tests to ensure proper new SEED value is saved
- Removed older tests for `rand()`
@enusbaum
Copy link
Member Author

Verified it's the same stdlib routine embedded within majorbbs.exe:

image

/// While the seed stored in memory is a 32-bit long, only the lower 16-bits are set
/// via the srand() method. The high 16-bits are always set to zero.
///
/// Signature: void srabd(int seed)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signature: void srand(int seed)

@enusbaum enusbaum merged commit 83268d3 into master Jul 15, 2023
1 check passed
@enusbaum enusbaum deleted the borland-rand branch July 15, 2023 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants