René's URL Explorer Experiment


Title: : uniform_real_distribution(a, b) produces outputs outside [a, b) · Issue #1074 · microsoft/STL · GitHub

Open Graph Title: : uniform_real_distribution(a, b) produces outputs outside [a, b) · Issue #1074 · microsoft/STL

X Title: : uniform_real_distribution(a, b) produces outputs outside [a, b) · Issue #1074 · microsoft/STL

Description: Describe the bug Produces random floating-point values i, uniformly distributed on the interval [a, b) cppreference.com The below code sample demonstrates how a default-constructed uniform_real_distribution (a=0, b=1) generates a ...

Open Graph Description: Describe the bug Produces random floating-point values i, uniformly distributed on the interval [a, b) cppreference.com The below code sample demonstrates how a default-constructed uniform_real_dis...

X Description: Describe the bug Produces random floating-point values i, uniformly distributed on the interval [a, b) cppreference.com The below code sample demonstrates how a default-constructed uniform_real_dis...

Opengraph URL: https://github.com/microsoft/STL/issues/1074

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"\u003crandom\u003e: uniform_real_distribution(a, b) produces outputs outside [a, b)","articleBody":"**Describe the bug**\r\n\u003e Produces random floating-point values i, uniformly distributed on the interval [a, b)\r\n\r\n*[cppreference.com](https://en.cppreference.com/w/cpp/numeric/random/uniform_real_distribution)*\r\n\r\nThe below code sample demonstrates how a default-constructed `uniform_real_distribution\u003cfloat\u003e` (a=0, b=1) generates a `1.0f` if provided a random number with all bits set:\r\n\r\n**Command-line test case**\r\n```\r\n#include \u003ccassert\u003e\r\n#include \u003ccstdint\u003e\r\n#include \u003climits\u003e\r\n#include \u003crandom\u003e\r\n\r\nstruct max_rng\r\n{\r\n\tusing result_type = std::uint32_t;\r\n\tresult_type min() const { return 0; }\r\n\tresult_type max() const { return std::numeric_limits\u003cresult_type\u003e::max(); }\r\n\tresult_type operator()() { return max(); }\r\n};\r\n\r\nint main()\r\n{\r\n\tmax_rng rng;\r\n\tstd::uniform_real_distribution\u003cfloat\u003e iid;\r\n\r\n\tassert(iid(rng) \u003c 1.0f);\r\n\r\n\treturn 0;\r\n}\r\n```\r\n\r\n**Expected behavior**\r\nRegardless of the input received from the RNG, `uniform_real_distribution` should never produce `b` as the interval is supposed to be right-*exclusive*. GCC passes this test.\r\n\r\n**STL version**\r\nMicrosoft Visual Studio Community 2019\r\nVersion 16.6.4\r\n\r\n**Additional context**\r\nThe error seems to originate from [`generate_canonical`](https://github.com/microsoft/STL/blob/c10ae01b4d9508eed9d5f059a120ee7223b6ac12/stl/inc/random#L261), which, when passed in the above code, simplifies down to:\r\n\r\n```\r\nreturn (float) UINT_MAX / (UINT_MAX + 1.0f);\r\n```\r\nwhich, mathematically speaking, *should* be less than 1, but in practice gets rounded to `1.0f` due to limited floating point precision. `generate_canonical` is flawed in other regards: using a normalizing/scaling division leads to non-uniformly distributed values. Both of these issues could be avoided by generating random floats the \"canonical\" way, which is to set the bits of the mantissa directly (and simply throw away left-over entropy) along the lines of:\r\n```\r\n// @rnd: uniformly distributed 32bit unsigned int.\r\nreturn (rnd \u003e\u003e 8) / 164233216.0f\r\n```\r\nwhich not only produces values strictly from [0, 1) for any value of `rnd`, but also makes sure that all values are equally far spaced apart leading to a perfect uniform distribution.\r\n\r\nAlso tracked by DevCom-110322 and Microsoft-internal VSO-253526 / [AB#253526](https://devdiv.visualstudio.com/0bdbc590-a062-4c3f-b0f6-9383f67865ee/_workitems/edit/253526) .\r\n","author":{"url":"https://github.com/denniskb","@type":"Person","name":"denniskb"},"datePublished":"2020-07-22T00:13:58.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/1074/STL/issues/1074"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:51d563c6-b12d-5c75-63f0-5ba7366b37b9
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idB8BE:2BDD1C:3C8BBBE:52653A4:6A44D3F4
html-safe-nonce8bb17e880a6fcb99ae294682b3a026ce55a3963e6388985acc4382c5ad253809
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOEJFOjJCREQxQzozQzhCQkJFOjUyNjUzQTQ6NkE0NEQzRjQiLCJ2aXNpdG9yX2lkIjoiMTcwNzA3MDA2MjUwNDIzNjAyMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacd659b9acb7771ccf95e927be8be227a7bf7efb0dba9e8196666c1983e4a581d5
hovercard-subject-tagissue:663384573
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/STL/1074/issue_layout
twitter:imagehttps://opengraph.githubassets.com/579f5dc027de6bc8d2c42bb4940b7f98121b897cc8ab56c64e3c1030adda0053/microsoft/STL/issues/1074
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/579f5dc027de6bc8d2c42bb4940b7f98121b897cc8ab56c64e3c1030adda0053/microsoft/STL/issues/1074
og:image:altDescribe the bug Produces random floating-point values i, uniformly distributed on the interval [a, b) cppreference.com The below code sample demonstrates how a default-constructed uniform_real_dis...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamedenniskb
hostnamegithub.com
expected-hostnamegithub.com
Noneb35ebc59c0fb02c2210b71c251a0894afe181fe7b14c0c156ba1cedcaddc6fe4
turbo-cache-controlno-preview
go-importgithub.com/microsoft/STL git https://github.com/microsoft/STL.git
octolytics-dimension-user_id6154722
octolytics-dimension-user_loginmicrosoft
octolytics-dimension-repository_id204593825
octolytics-dimension-repository_nwomicrosoft/STL
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id204593825
octolytics-dimension-repository_network_root_nwomicrosoft/STL
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release6b5b645842c42bc7b218f10a0557cffe9f81c436
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/microsoft/STL/issues/1074#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FSTL%2Fissues%2F1074
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FSTL%2Fissues%2F1074
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=microsoft%2FSTL
Reloadhttps://github.com/microsoft/STL/issues/1074
Reloadhttps://github.com/microsoft/STL/issues/1074
Reloadhttps://github.com/microsoft/STL/issues/1074
Please reload this pagehttps://github.com/microsoft/STL/issues/1074
microsoft https://github.com/microsoft
STLhttps://github.com/microsoft/STL
Notifications https://github.com/login?return_to=%2Fmicrosoft%2FSTL
Fork 1.6k https://github.com/login?return_to=%2Fmicrosoft%2FSTL
Star 11.1k https://github.com/login?return_to=%2Fmicrosoft%2FSTL
Code https://github.com/microsoft/STL
Issues 566 https://github.com/microsoft/STL/issues
Pull requests 22 https://github.com/microsoft/STL/pulls
Discussions https://github.com/microsoft/STL/discussions
Actions https://github.com/microsoft/STL/actions
Projects https://github.com/microsoft/STL/projects
Wiki https://github.com/microsoft/STL/wiki
Security and quality 0 https://github.com/microsoft/STL/security
Insights https://github.com/microsoft/STL/pulse
Code https://github.com/microsoft/STL
Issues https://github.com/microsoft/STL/issues
Pull requests https://github.com/microsoft/STL/pulls
Discussions https://github.com/microsoft/STL/discussions
Actions https://github.com/microsoft/STL/actions
Projects https://github.com/microsoft/STL/projects
Wiki https://github.com/microsoft/STL/wiki
Security and quality https://github.com/microsoft/STL/security
Insights https://github.com/microsoft/STL/pulse
#4740https://github.com/microsoft/STL/pull/4740
: uniform_real_distribution(a, b) produces outputs outside [a, b)https://github.com/microsoft/STL/issues/1074#top
#4740https://github.com/microsoft/STL/pull/4740
bugSomething isn't workinghttps://github.com/microsoft/STL/issues?q=state%3Aopen%20label%3A%22bug%22
fixedSomething works now, yay!https://github.com/microsoft/STL/issues?q=state%3Aopen%20label%3A%22fixed%22
https://github.com/denniskb
denniskbhttps://github.com/denniskb
on Jul 22, 2020https://github.com/microsoft/STL/issues/1074#issue-663384573
cppreference.comhttps://en.cppreference.com/w/cpp/numeric/random/uniform_real_distribution
generate_canonicalhttps://github.com/microsoft/STL/blob/c10ae01b4d9508eed9d5f059a120ee7223b6ac12/stl/inc/random#L261
DevCom-110322https://developercommunity.visualstudio.com/t/110322
VSO-253526https://devdiv.visualstudio.com/DevDiv/_workitems/edit/253526
AB#253526https://devdiv.visualstudio.com/0bdbc590-a062-4c3f-b0f6-9383f67865ee/_workitems/edit/253526
bugSomething isn't workinghttps://github.com/microsoft/STL/issues?q=state%3Aopen%20label%3A%22bug%22
fixedSomething works now, yay!https://github.com/microsoft/STL/issues?q=state%3Aopen%20label%3A%22fixed%22
Give feedbackhttps://github.com/orgs/community/discussions/189141
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.