{"id":17070367,"url":"https://github.com/owainkenwayucl/cobol-rand","last_synced_at":"2026-02-09T17:01:28.157Z","repository":{"id":81521995,"uuid":"76477066","full_name":"owainkenwayucl/cobol-rand","owner":"owainkenwayucl","description":"Experiment showing that Ubuntu Xenial's open-cobol package has a broken RNG","archived":false,"fork":false,"pushed_at":"2017-10-25T12:38:53.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-25T05:27:14.368Z","etag":null,"topics":["bug","cobol","fortran","rng","ubuntu","ubuntu-packages"],"latest_commit_sha":null,"homepage":null,"language":"COBOL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/owainkenwayucl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-12-14T16:27:28.000Z","updated_at":"2020-04-09T09:25:26.000Z","dependencies_parsed_at":"2023-09-25T00:59:16.869Z","dependency_job_id":null,"html_url":"https://github.com/owainkenwayucl/cobol-rand","commit_stats":{"total_commits":8,"total_committers":1,"mean_commits":8.0,"dds":0.0,"last_synced_commit":"d6f5db2c471c31af3591a5c7d1bf82ae3b6c9705"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/owainkenwayucl/cobol-rand","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owainkenwayucl%2Fcobol-rand","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owainkenwayucl%2Fcobol-rand/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owainkenwayucl%2Fcobol-rand/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owainkenwayucl%2Fcobol-rand/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/owainkenwayucl","download_url":"https://codeload.github.com/owainkenwayucl/cobol-rand/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owainkenwayucl%2Fcobol-rand/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29273139,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-09T13:47:44.167Z","status":"ssl_error","status_checked_at":"2026-02-09T13:47:43.721Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bug","cobol","fortran","rng","ubuntu","ubuntu-packages"],"created_at":"2024-10-14T11:30:44.291Z","updated_at":"2026-02-09T17:01:25.132Z","avatar_url":"https://github.com/owainkenwayucl.png","language":"COBOL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cobol-rand\nExperiment showing that Ubuntu Xenial's open-cobol package has a broken RNG.\n\nOne of the things I sometimes like to do with a new programming language is play with generating Pi by various methods.  Since Dr Kirker had already implementend our [canonical Pi example](https://github.com/UCL-RITS/pi_examples/blob/master/cobol_pi_dir/cobol_pi.cbl) I thought I'd do the Monte Carlo version in COBOL.  Unfortunately, I discovered a really interesting bug with the Open Cobol compiler provided as part of the Ubuntu Xenial packages:\n\n```\n$ dpkg -s open-cobol\nPackage: open-cobol\nStatus: install ok installed\nPriority: extra\nSection: devel\nInstalled-Size: 553\nMaintainer: Ubuntu Developers \u003cubuntu-devel-discuss@lists.ubuntu.com\u003e\nArchitecture: amd64\nVersion: 1.1-1build2\nDepends: libc6 (\u003e= 2.14), libcob1, libcob1-dev (= 1.1-1build2), libgmp3-dev, libltdl3-dev, libdb-dev, libncurses5-dev\nDescription: COBOL compiler\n OpenCOBOL implements substantial part of the COBOL 85 and COBOL 2002\n standards, as well as many extensions of the existent compilers.  OpenCOBOL\n translates COBOL into C and compiles the translated code using GCC.\nHomepage: http://www.opencobol.org/\nOriginal-Maintainer: Bart Martens \u003cbartm@debian.org\u003e\n$ cobc -V\ncobc (OpenCOBOL) 1.1.0\nCopyright (C) 2001-2009 Keisuke Nishida / Roger While\nBuilt    Feb 07 2016 10:28:13\nPackaged Feb 06 2009 10:30:55 CET\n``` \n\nThis bug results in the [RANDOM](http://www.ibm.com/support/knowledgecenter/en/SS6SG3_3.4.0/com.ibm.entcobol.doc_3.4/rlinfrnd.htm) function returning a skewed distribution rather than a uniform one.  This bug has been known about since [at least 2014](https://sourceforge.net/p/open-cobol/bugs/72/) but a fix hasn't made its way into the Ubuntu packages yet.\n\nTo show how bad it is, I've written a short COBOL program to generate 10,000,000 random numbers and then used R to plot them.  All the code is provided in this repository.  You can either build/run it by hand, or more simply if you have a system with GNU make installed, just run `make`.\n\n```\n$ make\ncobc -o genrand.exe -x -free genrand.cbl\n./genrand.exe \u003e genrand.out\nRscript plot.R genrand.out hist.png\nnull device \n          1 \ngfortran -c cobsupport.f\ncobc -g -o fortrand.exe -x -free fortrand.cbl cobsupport.o -lgfortran\n./fortrand.exe \u003e genfort.out\nRscript plot.R genfort.out histfort.png\nnull device \n          1 \n```\n\nThis wil compile the code with `cobc` and then use R to plot a `histogram.png` like the one below:\n\n![Histogram of output of COBOL RANDOM function](histogram.png)\n\nAs we can see, the skew towards lower values is pretty spectacular.  The net result is that if you are using the compiler that comes out of the Ubuntu repos, you should probably link to C (or better Fortran!) to do your random number generation.\n\nThe histogram below shows what happens when you call Fortran's `rand()`.\n\n![Histogram of output of Fortran's rand function](histogramf.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fowainkenwayucl%2Fcobol-rand","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fowainkenwayucl%2Fcobol-rand","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fowainkenwayucl%2Fcobol-rand/lists"}