Skip to content

fix: Use internal seed for RANDOM on GC3.2#406

Merged
meyfa merged 1 commit into
meyfa:mainfrom
GitMensch:patch-5
Mar 8, 2026
Merged

fix: Use internal seed for RANDOM on GC3.2#406
meyfa merged 1 commit into
meyfa:mainfrom
GitMensch:patch-5

Conversation

@GitMensch
Copy link
Copy Markdown
Contributor

@GitMensch GitMensch commented Feb 19, 2026

The seed needs to be a numeric value, not a substring containing numeric data ... and let GC3.2 do its magic of self-seeding

@meyfa
Copy link
Copy Markdown
Owner

meyfa commented Mar 8, 2026

Nice find! I had only looked at the outdated HTML version of the GnuCOBOL Programmer's Guide, which is for GC 3.1 RC-1 and states:

It is worth mentioning that if the first execution of RANDOM in your program lacks a seed argument, the result will be exactly as if that execution were coded with a seed argument value of 1.

The newer one available here (https://gnucobol.sourceforge.io/guides.html) states:

If you do not use a seed then the RANDOM function will automatically determine an internal
different seed at each execution.

Confirming that on GC 3.2, manual seeding is not required.

However, both versions of the guide also state:

If seed is alphanumeric, a value for it will be determined as if it were used as an argument to NUMVAL [...]

Which leads me to believe that the previous code was not incorrect, although of course there is no harm in being explicit.

Comment thread src/world/world.cob Outdated
Comment thread src/world/world.cob Outdated
@GitMensch
Copy link
Copy Markdown
Contributor Author

both versions of the guide also state:

If seed is alphanumeric, a value for it will be determined as if it were used as an argument to NUMVAL [...]

Which leads me to believe that the previous code was not incorrect, although of course there is no harm in being explicit.

Note that this is an extension - if you look at the standard (I was allowed to share the draft, so we have kind of an "open" definition) and at most (all?`) other language references you'll see the hard rule (which is the reason that the code did not compile on other environments).

side-note: The standard reference was missing in our internal doc, so I've created https://sourceforge.net/p/gnucobol/bugs/1202/ to allow it to be fixed. Thanks for pointing that out.

I've included your suggestions but that's now 3 commits - feel free to close and just directly edit the lines with the result or squash-merge.

which needs to be a numeric value, not a substring containing numeric data
... and let GC3.2 do its magic of self-seeding
@meyfa
Copy link
Copy Markdown
Owner

meyfa commented Mar 8, 2026

That's awesome! Thanks for sharing the draft!

Copy link
Copy Markdown
Owner

@meyfa meyfa left a comment

Choose a reason for hiding this comment

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

LGTM and test OK

@meyfa meyfa changed the title correct type for FUNCTION RANDOM fix: Use internal seed for RANDOM on GC3.2 Mar 8, 2026
@meyfa meyfa merged commit c6f34f9 into meyfa:main Mar 8, 2026
5 checks passed
@GitMensch GitMensch deleted the patch-5 branch March 8, 2026 09:36
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