squiggle.c/references/Box–Muller_transform

1653 lines
121 KiB
Plaintext
Raw Permalink Normal View History

2023-12-03 18:46:24 +00:00
<!DOCTYPE html>
<html class="client-nojs vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-zebra-design-disabled vector-feature-custom-font-size-clientpref-0 vector-feature-client-preferences-disabled vector-feature-typography-survey-disabled vector-toc-available" lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<title>BoxMuller transform - Wikipedia</title>
<script>(function(){var className="client-js vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-zebra-design-disabled vector-feature-custom-font-size-clientpref-0 vector-feature-client-preferences-disabled vector-feature-typography-survey-disabled vector-toc-available";var cookie=document.cookie.match(/(?:^|; )enwikimwclientpreferences=([^;]+)/);if(cookie){cookie[1].split('%2C').forEach(function(pref){className=className.replace(new RegExp('(^| )'+pref.replace(/-clientpref-\w+$|[^\w-]+/g,'')+'-clientpref-\\w+( |$)'),'$1'+pref+'$2');});}document.documentElement.className=className;}());RLCONF={"wgBreakFrames":false,"wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],
"wgDefaultDateFormat":"dmy","wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgRequestId":"42a7db9c-e419-4665-938e-75af5015b88d","wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"BoxMuller_transform","wgTitle":"BoxMuller transform","wgCurRevisionId":1184897234,"wgRevisionId":1184897234,"wgArticleId":60758,"wgIsArticle":true,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["Articles with short description","Short description matches Wikidata","Articles with example C++ code","Transforms","Non-uniform random numbers"],"wgPageViewLanguage":"en","wgPageContentLanguage":"en","wgPageContentModel":"wikitext","wgRelevantPageName":"BoxMuller_transform","wgRelevantArticleId":60758,"wgIsProbablyEditable":true,"wgRelevantPageIsProbablyEditable":true,"wgRestrictionEdit":[],"wgRestrictionMove":[],"wgNoticeProject":
"wikipedia","wgFlaggedRevsParams":{"tags":{"status":{"levels":1}}},"wgMediaViewerOnClick":true,"wgMediaViewerEnabledByDefault":true,"wgPopupsFlags":6,"wgVisualEditor":{"pageLanguageCode":"en","pageLanguageDir":"ltr","pageVariantFallbacks":"en"},"wgMFDisplayWikibaseDescriptions":{"search":true,"watchlist":true,"tagline":false,"nearby":true},"wgWMESchemaEditAttemptStepOversample":false,"wgWMEPageLength":10000,"wgULSCurrentAutonym":"English","wgCentralAuthMobileDomain":false,"wgEditSubmitButtonLabelPublish":true,"wgULSPosition":"interlanguage","wgULSisCompactLinksEnabled":true,"wgULSisLanguageSelectorEmpty":false,"wgWikibaseItemId":"Q895514","wgCheckUserClientHintsHeadersJsApi":["architecture","bitness","brands","fullVersionList","mobile","model","platform","platformVersion"],"GEHomepageSuggestedEditsEnableTopics":true,"wgGETopicsMatchModeEnabled":false,"wgGEStructuredTaskRejectionReasonTextInputEnabled":false,"wgGELevelingUpEnabledForUser":false};RLSTATE={"skins.vector.user.styles":
"ready","ext.globalCssJs.user.styles":"ready","site.styles":"ready","user.styles":"ready","skins.vector.user":"ready","ext.globalCssJs.user":"ready","user":"ready","user.options":"loading","ext.cite.styles":"ready","ext.math.styles":"ready","ext.pygments":"ready","codex-search-styles":"ready","skins.vector.styles":"ready","skins.vector.icons":"ready","ext.visualEditor.desktopArticleTarget.noscript":"ready","ext.uls.interlanguage":"ready","wikibase.client.init":"ready","ext.wikimediaBadges":"ready"};RLPAGEMODULES=["ext.cite.ux-enhancements","mediawiki.page.media","ext.scribunto.logs","site","mediawiki.page.ready","mediawiki.toc","skins.vector.js","ext.centralNotice.geoIP","ext.centralNotice.startUp","ext.gadget.ReferenceTooltips","ext.gadget.switcher","ext.urlShortener.toolbar","ext.centralauth.centralautologin","mmv.head","mmv.bootstrap.autostart","ext.popups","ext.visualEditor.desktopArticleTarget.init","ext.visualEditor.targetLoader","ext.echo.centralauth","ext.eventLogging",
"ext.wikimediaEvents","ext.navigationTiming","ext.uls.compactlinks","ext.uls.interface","ext.cx.eventlogging.campaigns","ext.cx.uls.quick.actions","wikibase.client.vector-2022","ext.checkUser.clientHints","ext.growthExperiments.SuggestedEditSession"];</script>
<script>(RLQ=window.RLQ||[]).push(function(){mw.loader.impl(function(){return["user.options@12s5i",function($,jQuery,require,module){mw.user.tokens.set({"patrolToken":"+\\","watchToken":"+\\","csrfToken":"+\\"});
}];});});</script>
<link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=codex-search-styles%7Cext.cite.styles%7Cext.math.styles%7Cext.pygments%2CwikimediaBadges%7Cext.uls.interlanguage%7Cext.visualEditor.desktopArticleTarget.noscript%7Cskins.vector.icons%2Cstyles%7Cwikibase.client.init&amp;only=styles&amp;skin=vector-2022">
<script async="" src="/w/load.php?lang=en&amp;modules=startup&amp;only=scripts&amp;raw=1&amp;skin=vector-2022"></script>
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=site.styles&amp;only=styles&amp;skin=vector-2022">
<meta name="generator" content="MediaWiki 1.42.0-wmf.5">
<meta name="referrer" content="origin">
<meta name="referrer" content="origin-when-cross-origin">
<meta name="robots" content="max-image-preview:standard">
<meta name="format-detection" content="telephone=no">
<meta property="og:image" content="https://upload.wikimedia.org/wikipedia/commons/thumb/1/1f/Box-Muller_transform_visualisation.svg/1200px-Box-Muller_transform_visualisation.svg.png">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="1200">
<meta property="og:image" content="https://upload.wikimedia.org/wikipedia/commons/thumb/1/1f/Box-Muller_transform_visualisation.svg/800px-Box-Muller_transform_visualisation.svg.png">
<meta property="og:image:width" content="800">
<meta property="og:image:height" content="800">
<meta property="og:image" content="https://upload.wikimedia.org/wikipedia/commons/thumb/1/1f/Box-Muller_transform_visualisation.svg/640px-Box-Muller_transform_visualisation.svg.png">
<meta property="og:image:width" content="640">
<meta property="og:image:height" content="640">
<meta name="viewport" content="width=1000">
<meta property="og:title" content="BoxMuller transform - Wikipedia">
<meta property="og:type" content="website">
<link rel="preconnect" href="//upload.wikimedia.org">
<link rel="alternate" media="only screen and (max-width: 720px)" href="//en.m.wikipedia.org/wiki/Box%E2%80%93Muller_transform">
<link rel="alternate" type="application/x-wiki" title="Edit this page" href="/w/index.php?title=Box%E2%80%93Muller_transform&amp;action=edit">
<link rel="apple-touch-icon" href="/static/apple-touch/wikipedia.png">
<link rel="icon" href="/static/favicon/wikipedia.ico">
<link rel="search" type="application/opensearchdescription+xml" href="/w/opensearch_desc.php" title="Wikipedia (en)">
<link rel="EditURI" type="application/rsd+xml" href="//en.wikipedia.org/w/api.php?action=rsd">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform">
<link rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">
<link rel="alternate" type="application/atom+xml" title="Wikipedia Atom feed" href="/w/index.php?title=Special:RecentChanges&amp;feed=atom">
<link rel="dns-prefetch" href="//meta.wikimedia.org" />
<link rel="dns-prefetch" href="//login.wikimedia.org">
</head>
<body class="skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject mw-editable page-BoxMuller_transform rootpage-BoxMuller_transform skin-vector-2022 action-view"><a class="mw-jump-link" href="#bodyContent">Jump to content</a>
<div class="vector-header-container">
<header class="vector-header mw-header">
<div class="vector-header-start">
<nav class="vector-main-menu-landmark" aria-label="Site" role="navigation">
<div id="vector-main-menu-dropdown" class="vector-dropdown vector-main-menu-dropdown vector-button-flush-left vector-button-flush-right" >
<input type="checkbox" id="vector-main-menu-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-main-menu-dropdown" class="vector-dropdown-checkbox " aria-label="Main menu" >
<label id="vector-main-menu-dropdown-label" for="vector-main-menu-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-menu mw-ui-icon-wikimedia-menu"></span>
<span class="vector-dropdown-label-text">Main menu</span>
</label>
<div class="vector-dropdown-content">
<div id="vector-main-menu-unpinned-container" class="vector-unpinned-container">
<div id="vector-main-menu" class="vector-main-menu vector-pinnable-element">
<div
class="vector-pinnable-header vector-main-menu-pinnable-header vector-pinnable-header-unpinned"
data-feature-name="main-menu-pinned"
data-pinnable-element-id="vector-main-menu"
data-pinned-container-id="vector-main-menu-pinned-container"
data-unpinned-container-id="vector-main-menu-unpinned-container"
>
<div class="vector-pinnable-header-label">Main menu</div>
<button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-main-menu.pin">move to sidebar</button>
<button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-main-menu.unpin">hide</button>
</div>
<div id="p-navigation" class="vector-menu mw-portlet mw-portlet-navigation" >
<div class="vector-menu-heading">
Navigation
</div>
<div class="vector-menu-content">
<ul class="vector-menu-content-list">
<li id="n-mainpage-description" class="mw-list-item"><a href="/wiki/Main_Page" title="Visit the main page [z]" accesskey="z"><span>Main page</span></a></li><li id="n-contents" class="mw-list-item"><a href="/wiki/Wikipedia:Contents" title="Guides to browsing Wikipedia"><span>Contents</span></a></li><li id="n-currentevents" class="mw-list-item"><a href="/wiki/Portal:Current_events" title="Articles related to current events"><span>Current events</span></a></li><li id="n-randompage" class="mw-list-item"><a href="/wiki/Special:Random" title="Visit a randomly selected article [x]" accesskey="x"><span>Random article</span></a></li><li id="n-aboutsite" class="mw-list-item"><a href="/wiki/Wikipedia:About" title="Learn about Wikipedia and how it works"><span>About Wikipedia</span></a></li><li id="n-contactpage" class="mw-list-item"><a href="//en.wikipedia.org/wiki/Wikipedia:Contact_us" title="How to contact Wikipedia"><span>Contact us</span></a></li><li id="n-sitesupport" class="mw-list-item"><a href="https://donate.wikimedia.org/wiki/Special:FundraiserRedirector?utm_source=donate&amp;utm_medium=sidebar&amp;utm_campaign=C13_en.wikipedia.org&amp;uselang=en" title="Support us by donating to the Wikimedia Foundation"><span>Donate</span></a></li>
</ul>
</div>
</div>
<div id="p-interaction" class="vector-menu mw-portlet mw-portlet-interaction" >
<div class="vector-menu-heading">
Contribute
</div>
<div class="vector-menu-content">
<ul class="vector-menu-content-list">
<li id="n-help" class="mw-list-item"><a href="/wiki/Help:Contents" title="Guidance on how to use and edit Wikipedia"><span>Help</span></a></li><li id="n-introduction" class="mw-list-item"><a href="/wiki/Help:Introduction" title="Learn how to edit Wikipedia"><span>Learn to edit</span></a></li><li id="n-portal" class="mw-list-item"><a href="/wiki/Wikipedia:Community_portal" title="The hub for editors"><span>Community portal</span></a></li><li id="n-recentchanges" class="mw-list-item"><a href="/wiki/Special:RecentChanges" title="A list of recent changes to Wikipedia [r]" accesskey="r"><span>Recent changes</span></a></li><li id="n-upload" class="mw-list-item"><a href="/wiki/Wikipedia:File_upload_wizard" title="Add images or other media for use on Wikipedia"><span>Upload file</span></a></li>
</ul>
</div>
</div>
<div class="vector-main-menu-action vector-main-menu-action-lang-alert">
<div class="vector-main-menu-action-item">
<div class="vector-main-menu-action-heading vector-menu-heading">Languages</div>
<div class="vector-main-menu-action-content vector-menu-content">
<div class="mw-message-box cdx-message cdx-message--block mw-message-box-notice cdx-message--notice vector-language-sidebar-alert"><span class="cdx-message__icon"></span><div class="cdx-message__content">Language links are at the top of the page across from the title.</div></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</nav>
<a href="/wiki/Main_Page" class="mw-logo">
<img class="mw-logo-icon" src="/static/images/icons/wikipedia.png" alt="" aria-hidden="true" height="50" width="50">
<span class="mw-logo-container">
<img class="mw-logo-wordmark" alt="Wikipedia" src="/static/images/mobile/copyright/wikipedia-wordmark-en.svg" style="width: 7.5em; height: 1.125em;">
<img class="mw-logo-tagline" alt="The Free Encyclopedia" src="/static/images/mobile/copyright/wikipedia-tagline-en.svg" width="117" height="13" style="width: 7.3125em; height: 0.8125em;">
</span>
</a>
</div>
<div class="vector-header-end">
<div id="p-search" role="search" class="vector-search-box-vue vector-search-box-collapses vector-search-box-show-thumbnail vector-search-box-auto-expand-width vector-search-box">
<a href="/wiki/Special:Search" class="cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only search-toggle" id="" title="Search Wikipedia [f]" accesskey="f"><span class="vector-icon mw-ui-icon-search mw-ui-icon-wikimedia-search"></span>
<span>Search</span>
</a>
<div class="vector-typeahead-search-container">
<div class="cdx-typeahead-search cdx-typeahead-search--show-thumbnail cdx-typeahead-search--auto-expand-width">
<form action="/w/index.php" id="searchform" class="cdx-search-input cdx-search-input--has-end-button">
<div id="simpleSearch" class="cdx-search-input__input-wrapper" data-search-loc="header-moved">
<div class="cdx-text-input cdx-text-input--has-start-icon">
<input
class="cdx-text-input__input"
type="search" name="search" placeholder="Search Wikipedia" aria-label="Search Wikipedia" autocapitalize="sentences" title="Search Wikipedia [f]" accesskey="f" id="searchInput"
>
<span class="cdx-text-input__icon cdx-text-input__start-icon"></span>
</div>
<input type="hidden" name="title" value="Special:Search">
</div>
<button class="cdx-button cdx-search-input__end-button">Search</button>
</form>
</div>
</div>
</div>
<nav class="vector-user-links vector-user-links-wide" aria-label="Personal tools" role="navigation" >
<div class="vector-user-links-main">
<div id="p-vector-user-menu-preferences" class="vector-menu mw-portlet emptyPortlet" >
<div class="vector-menu-content">
<ul class="vector-menu-content-list">
</ul>
</div>
</div>
<div id="p-vector-user-menu-userpage" class="vector-menu mw-portlet emptyPortlet" >
<div class="vector-menu-content">
<ul class="vector-menu-content-list">
</ul>
</div>
</div>
<div id="p-vector-user-menu-notifications" class="vector-menu mw-portlet emptyPortlet" >
<div class="vector-menu-content">
<ul class="vector-menu-content-list">
</ul>
</div>
</div>
<div id="p-vector-user-menu-overflow" class="vector-menu mw-portlet" >
<div class="vector-menu-content">
<ul class="vector-menu-content-list">
<li id="pt-createaccount-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="/w/index.php?title=Special:CreateAccount&amp;returnto=Box%E2%80%93Muller+transform" title="You are encouraged to create an account and log in; however, it is not mandatory" class=""><span>Create account</span></a>
</li>
<li id="pt-login-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="/w/index.php?title=Special:UserLogin&amp;returnto=Box%E2%80%93Muller+transform" title="You&#039;re encouraged to log in; however, it&#039;s not mandatory. [o]" accesskey="o" class=""><span>Log in</span></a>
</li>
</ul>
</div>
</div>
</div>
<div id="vector-user-links-dropdown" class="vector-dropdown vector-user-menu vector-button-flush-right vector-user-menu-logged-out" title="Log in and more options" >
<input type="checkbox" id="vector-user-links-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-user-links-dropdown" class="vector-dropdown-checkbox " aria-label="Personal tools" >
<label id="vector-user-links-dropdown-label" for="vector-user-links-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-ellipsis mw-ui-icon-wikimedia-ellipsis"></span>
<span class="vector-dropdown-label-text">Personal tools</span>
</label>
<div class="vector-dropdown-content">
<div id="p-personal" class="vector-menu mw-portlet mw-portlet-personal user-links-collapsible-item" title="User menu" >
<div class="vector-menu-content">
<ul class="vector-menu-content-list">
<li id="pt-createaccount" class="user-links-collapsible-item mw-list-item"><a href="/w/index.php?title=Special:CreateAccount&amp;returnto=Box%E2%80%93Muller+transform" title="You are encouraged to create an account and log in; however, it is not mandatory"><span class="vector-icon mw-ui-icon-userAdd mw-ui-icon-wikimedia-userAdd"></span> <span>Create account</span></a></li><li id="pt-login" class="user-links-collapsible-item mw-list-item"><a href="/w/index.php?title=Special:UserLogin&amp;returnto=Box%E2%80%93Muller+transform" title="You&#039;re encouraged to log in; however, it&#039;s not mandatory. [o]" accesskey="o"><span class="vector-icon mw-ui-icon-logIn mw-ui-icon-wikimedia-logIn"></span> <span>Log in</span></a></li>
</ul>
</div>
</div>
<div id="p-user-menu-anon-editor" class="vector-menu mw-portlet mw-portlet-user-menu-anon-editor" >
<div class="vector-menu-heading">
Pages for logged out editors <a href="/wiki/Help:Introduction" aria-label="Learn more about editing"><span>learn more</span></a>
</div>
<div class="vector-menu-content">
<ul class="vector-menu-content-list">
<li id="pt-anoncontribs" class="mw-list-item"><a href="/wiki/Special:MyContributions" title="A list of edits made from this IP address [y]" accesskey="y"><span>Contributions</span></a></li><li id="pt-anontalk" class="mw-list-item"><a href="/wiki/Special:MyTalk" title="Discussion about edits from this IP address [n]" accesskey="n"><span>Talk</span></a></li>
</ul>
</div>
</div>
</div>
</div>
</nav>
</div>
</header>
</div>
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="vector-sitenotice-container">
<div id="siteNotice"><!-- CentralNotice --></div>
</div>
<div class="vector-main-menu-container">
<div id="mw-navigation">
<nav id="mw-panel" class="vector-main-menu-landmark" aria-label="Site" role="navigation">
<div id="vector-main-menu-pinned-container" class="vector-pinned-container">
</div>
</nav>
</div>
</div>
<nav id="mw-panel-toc" role="navigation" aria-label="Contents" data-event-name="ui.sidebar-toc" class="mw-table-of-contents-container vector-toc-landmark vector-sticky-pinned-container">
<div id="vector-toc-pinned-container" class="vector-pinned-container">
<div id="vector-toc" class="vector-toc vector-pinnable-element">
<div
class="vector-pinnable-header vector-toc-pinnable-header vector-pinnable-header-pinned"
data-feature-name="toc-pinned"
data-pinnable-element-id="vector-toc"
>
<h2 class="vector-pinnable-header-label">Contents</h2>
<button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-toc.pin">move to sidebar</button>
<button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-toc.unpin">hide</button>
</div>
<ul class="vector-toc-contents" id="mw-panel-toc-list">
<li id="toc-mw-content-text"
class="vector-toc-list-item vector-toc-level-1">
<a href="#" class="vector-toc-link">
<div class="vector-toc-text">(Top)</div>
</a>
</li>
<li id="toc-Basic_form"
class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded">
<a class="vector-toc-link" href="#Basic_form">
<div class="vector-toc-text">
<span class="vector-toc-numb">1</span>Basic form</div>
</a>
<ul id="toc-Basic_form-sublist" class="vector-toc-list">
</ul>
</li>
<li id="toc-Polar_form"
class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded">
<a class="vector-toc-link" href="#Polar_form">
<div class="vector-toc-text">
<span class="vector-toc-numb">2</span>Polar form</div>
</a>
<ul id="toc-Polar_form-sublist" class="vector-toc-list">
</ul>
</li>
<li id="toc-Contrasting_the_two_forms"
class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded">
<a class="vector-toc-link" href="#Contrasting_the_two_forms">
<div class="vector-toc-text">
<span class="vector-toc-numb">3</span>Contrasting the two forms</div>
</a>
<ul id="toc-Contrasting_the_two_forms-sublist" class="vector-toc-list">
</ul>
</li>
<li id="toc-Tails_truncation"
class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded">
<a class="vector-toc-link" href="#Tails_truncation">
<div class="vector-toc-text">
<span class="vector-toc-numb">4</span>Tails truncation</div>
</a>
<ul id="toc-Tails_truncation-sublist" class="vector-toc-list">
</ul>
</li>
<li id="toc-Implementation"
class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded">
<a class="vector-toc-link" href="#Implementation">
<div class="vector-toc-text">
<span class="vector-toc-numb">5</span>Implementation</div>
</a>
<ul id="toc-Implementation-sublist" class="vector-toc-list">
</ul>
</li>
<li id="toc-See_also"
class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded">
<a class="vector-toc-link" href="#See_also">
<div class="vector-toc-text">
<span class="vector-toc-numb">6</span>See also</div>
</a>
<ul id="toc-See_also-sublist" class="vector-toc-list">
</ul>
</li>
<li id="toc-References"
class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded">
<a class="vector-toc-link" href="#References">
<div class="vector-toc-text">
<span class="vector-toc-numb">7</span>References</div>
</a>
<ul id="toc-References-sublist" class="vector-toc-list">
</ul>
</li>
<li id="toc-External_links"
class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded">
<a class="vector-toc-link" href="#External_links">
<div class="vector-toc-text">
<span class="vector-toc-numb">8</span>External links</div>
</a>
<ul id="toc-External_links-sublist" class="vector-toc-list">
</ul>
</li>
</ul>
</div>
</div>
</nav>
<div class="mw-content-container">
<main id="content" class="mw-body" role="main">
<header class="mw-body-header vector-page-titlebar">
<nav role="navigation" aria-label="Contents" class="vector-toc-landmark">
<div id="vector-page-titlebar-toc" class="vector-dropdown vector-page-titlebar-toc vector-button-flush-left" >
<input type="checkbox" id="vector-page-titlebar-toc-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-page-titlebar-toc" class="vector-dropdown-checkbox " aria-label="Toggle the table of contents" >
<label id="vector-page-titlebar-toc-label" for="vector-page-titlebar-toc-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-listBullet mw-ui-icon-wikimedia-listBullet"></span>
<span class="vector-dropdown-label-text">Toggle the table of contents</span>
</label>
<div class="vector-dropdown-content">
<div id="vector-page-titlebar-toc-unpinned-container" class="vector-unpinned-container">
</div>
</div>
</div>
</nav>
<h1 id="firstHeading" class="firstHeading mw-first-heading"><span class="mw-page-title-main">BoxMuller transform</span></h1>
<div id="p-lang-btn" class="vector-dropdown mw-portlet mw-portlet-lang" >
<input type="checkbox" id="p-lang-btn-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-p-lang-btn" class="vector-dropdown-checkbox mw-interlanguage-selector" aria-label="Go to an article in another language. Available in 13 languages" >
<label id="p-lang-btn-label" for="p-lang-btn-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--action-progressive mw-portlet-lang-heading-13" aria-hidden="true" ><span class="vector-icon mw-ui-icon-language-progressive mw-ui-icon-wikimedia-language-progressive"></span>
<span class="vector-dropdown-label-text">13 languages</span>
</label>
<div class="vector-dropdown-content">
<div class="vector-menu-content">
<ul class="vector-menu-content-list">
<li class="interlanguage-link interwiki-ca mw-list-item"><a href="https://ca.wikipedia.org/wiki/Transformada_de_Box-Mulle" title="Transformada de Box-Mulle Catalan" lang="ca" hreflang="ca" class="interlanguage-link-target"><span>Català</span></a></li><li class="interlanguage-link interwiki-de mw-list-item"><a href="https://de.wikipedia.org/wiki/Box-Muller-Methode" title="Box-Muller-Methode German" lang="de" hreflang="de" class="interlanguage-link-target"><span>Deutsch</span></a></li><li class="interlanguage-link interwiki-es mw-list-item"><a href="https://es.wikipedia.org/wiki/M%C3%A9todo_de_Box-Muller" title="Método de Box-Muller Spanish" lang="es" hreflang="es" class="interlanguage-link-target"><span>Español</span></a></li><li class="interlanguage-link interwiki-fa mw-list-item"><a href="https://fa.wikipedia.org/wiki/%D8%AA%D8%A8%D8%AF%DB%8C%D9%84_%D8%A8%D8%A7%DA%A9%D8%B3-%D9%85%D9%88%D9%84%D8%B1" title="تبدیل باکس-مولر Persian" lang="fa" hreflang="fa" class="interlanguage-link-target"><span>فارسی</span></a></li><li class="interlanguage-link interwiki-fr mw-list-item"><a href="https://fr.wikipedia.org/wiki/M%C3%A9thode_de_Box-Muller" title="Méthode de Box-Muller French" lang="fr" hreflang="fr" class="interlanguage-link-target"><span>Français</span></a></li><li class="interlanguage-link interwiki-it mw-list-item"><a href="https://it.wikipedia.org/wiki/Trasformazione_di_Box-Muller" title="Trasformazione di Box-Muller Italian" lang="it" hreflang="it" class="interlanguage-link-target"><span>Italiano</span></a></li><li class="interlanguage-link interwiki-he mw-list-item"><a href="https://he.wikipedia.org/wiki/%D7%98%D7%A8%D7%A0%D7%A1%D7%A4%D7%95%D7%A8%D7%9E%D7%A6%D7%99%D7%99%D7%AA_%D7%91%D7%95%D7%A7%D7%A1-%D7%9E%D7%99%D7%9C%D7%A8" title="טרנספורמציית בוקס-מילר Hebrew" lang="he" hreflang="he" class="interlanguage-link-target"><span>עברית</span></a></li><li class="interlanguage-link interwiki-ja mw-list-item"><a href="https://ja.wikipedia.org/wiki/%E3%83%9C%E3%83%83%E3%82%AF%E3%82%B9%EF%BC%9D%E3%83%9F%E3%83%A5%E3%83%A9%E3%83%BC%E6%B3%95" title="ボックス=ミュラー法 Japanese" lang="ja" hreflang="ja" class="interlanguage-link-target"><span>日本語</span></a></li><li class="interlanguage-link interwiki-pl mw-list-item"><a href="https://pl.wikipedia.org/wiki/Transformacja_Boxa-Mullera" title="Transformacja Boxa-Mullera Polish" lang="pl" hreflang="pl" class="interlanguage-link-target"><span>Polski</span></a></li><li class="interlanguage-link interwiki-pt mw-list-item"><a href="https://pt.wikipedia.org/wiki/Transforma%C3%A7%C3%A3o_de_Box-Muller" title="Transformação de Box-Muller Portuguese" lang="pt" hreflang="pt" class="interlanguage-link-target"><span>Português</span></a></li><li class="interlanguage-link interwiki-ru mw-list-item"><a href="https://ru.wikipedia.org/wiki/%D0%9F%D1%80%D0%B5%D0%BE%D0%B1%D1%80%D0%B0%D0%B7%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5_%D0%91%D0%BE%D0%BA%D1%81%D0%B0_%E2%80%94_%D0%9C%D1%8E%D0%BB%D0%BB%D0%B5%D1%80%D0%B0" title="Преобразование Бокса — Мюллера Russian" lang="ru" hreflang="ru" class="interlanguage-link-target"><span>Русский</span></a></li><li class="interlanguage-link interwiki-su mw-list-item"><a href="https://su.wikipedia.org/wiki/Transformasi_Box-Muller" title="Transformasi Box-Muller Sundanese" lang="su" hreflang="su" class="interlanguage-link-target"><span>Sunda</span></a></li><li class="interlanguage-link interwiki-uk mw-list-item"><a href="https://uk.wikipedia.org/wiki/%D0%9F%D0%B5%D1%80%D0%B5%D1%82%D0%B2%D0%BE%D1%80%D0%B5%D0%BD%D0%BD%D1%8F_%D0%91%D0%BE%D0%BA%D1%81%D0%B0-%D0%9C%D1%8E%D0%BB%D0%BB%D0%B5%D1%80%D0%B0" title="Перетворення Бокса-Мюллера Ukrainian" lang="uk" hreflang="uk" class="interlanguage-link-target"><span>Українська</span></a></li>
</ul>
<div class="after-portlet after-portlet-lang"><span class="wb-langlinks-edit wb-langlinks-link"><a href="https://www.wikidata.org/wiki/Special:EntityPage/Q895514#sitelinks-wikipedia" title="Edit interlanguage links" class="wbc-editpage">Edit links</a></span></div>
</div>
</div>
</div>
</header>
<div class="vector-page-toolbar">
<div class="vector-page-toolbar-container">
<div id="left-navigation">
<nav aria-label="Namespaces">
<div id="p-associated-pages" class="vector-menu vector-menu-tabs mw-portlet mw-portlet-associated-pages" >
<div class="vector-menu-content">
<ul class="vector-menu-content-list">
<li id="ca-nstab-main" class="selected vector-tab-noicon mw-list-item"><a href="/wiki/Box%E2%80%93Muller_transform" title="View the content page [c]" accesskey="c"><span>Article</span></a></li><li id="ca-talk" class="vector-tab-noicon mw-list-item"><a href="/wiki/Talk:Box%E2%80%93Muller_transform" rel="discussion" title="Discuss improvements to the content page [t]" accesskey="t"><span>Talk</span></a></li>
</ul>
</div>
</div>
<div id="p-variants" class="vector-dropdown emptyPortlet" >
<input type="checkbox" id="p-variants-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-p-variants" class="vector-dropdown-checkbox " aria-label="Change language variant" >
<label id="p-variants-label" for="p-variants-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet" aria-hidden="true" ><span class="vector-dropdown-label-text">English</span>
</label>
<div class="vector-dropdown-content">
<div id="p-variants" class="vector-menu mw-portlet mw-portlet-variants emptyPortlet" >
<div class="vector-menu-content">
<ul class="vector-menu-content-list">
</ul>
</div>
</div>
</div>
</div>
</nav>
</div>
<div id="right-navigation" class="vector-collapsible">
<nav aria-label="Views">
<div id="p-views" class="vector-menu vector-menu-tabs mw-portlet mw-portlet-views" >
<div class="vector-menu-content">
<ul class="vector-menu-content-list">
<li id="ca-view" class="selected vector-tab-noicon mw-list-item"><a href="/wiki/Box%E2%80%93Muller_transform"><span>Read</span></a></li><li id="ca-edit" class="vector-tab-noicon mw-list-item"><a href="/w/index.php?title=Box%E2%80%93Muller_transform&amp;action=edit" title="Edit this page [e]" accesskey="e"><span>Edit</span></a></li><li id="ca-history" class="vector-tab-noicon mw-list-item"><a href="/w/index.php?title=Box%E2%80%93Muller_transform&amp;action=history" title="Past revisions of this page [h]" accesskey="h"><span>View history</span></a></li>
</ul>
</div>
</div>
</nav>
<nav class="vector-page-tools-landmark" aria-label="Page tools">
<div id="vector-page-tools-dropdown" class="vector-dropdown vector-page-tools-dropdown" >
<input type="checkbox" id="vector-page-tools-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-page-tools-dropdown" class="vector-dropdown-checkbox " aria-label="Tools" >
<label id="vector-page-tools-dropdown-label" for="vector-page-tools-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet" aria-hidden="true" ><span class="vector-dropdown-label-text">Tools</span>
</label>
<div class="vector-dropdown-content">
<div id="vector-page-tools-unpinned-container" class="vector-unpinned-container">
<div id="vector-page-tools" class="vector-page-tools vector-pinnable-element">
<div
class="vector-pinnable-header vector-page-tools-pinnable-header vector-pinnable-header-unpinned"
data-feature-name="page-tools-pinned"
data-pinnable-element-id="vector-page-tools"
data-pinned-container-id="vector-page-tools-pinned-container"
data-unpinned-container-id="vector-page-tools-unpinned-container"
>
<div class="vector-pinnable-header-label">Tools</div>
<button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-page-tools.pin">move to sidebar</button>
<button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-page-tools.unpin">hide</button>
</div>
<div id="p-cactions" class="vector-menu mw-portlet mw-portlet-cactions emptyPortlet vector-has-collapsible-items" title="More options" >
<div class="vector-menu-heading">
Actions
</div>
<div class="vector-menu-content">
<ul class="vector-menu-content-list">
<li id="ca-more-view" class="selected vector-more-collapsible-item mw-list-item"><a href="/wiki/Box%E2%80%93Muller_transform"><span>Read</span></a></li><li id="ca-more-edit" class="vector-more-collapsible-item mw-list-item"><a href="/w/index.php?title=Box%E2%80%93Muller_transform&amp;action=edit" title="Edit this page [e]" accesskey="e"><span>Edit</span></a></li><li id="ca-more-history" class="vector-more-collapsible-item mw-list-item"><a href="/w/index.php?title=Box%E2%80%93Muller_transform&amp;action=history"><span>View history</span></a></li>
</ul>
</div>
</div>
<div id="p-tb" class="vector-menu mw-portlet mw-portlet-tb" >
<div class="vector-menu-heading">
General
</div>
<div class="vector-menu-content">
<ul class="vector-menu-content-list">
<li id="t-whatlinkshere" class="mw-list-item"><a href="/wiki/Special:WhatLinksHere/Box%E2%80%93Muller_transform" title="List of all English Wikipedia pages containing links to this page [j]" accesskey="j"><span>What links here</span></a></li><li id="t-recentchangeslinked" class="mw-list-item"><a href="/wiki/Special:RecentChangesLinked/Box%E2%80%93Muller_transform" rel="nofollow" title="Recent changes in pages linked from this page [k]" accesskey="k"><span>Related changes</span></a></li><li id="t-upload" class="mw-list-item"><a href="/wiki/Wikipedia:File_Upload_Wizard" title="Upload files [u]" accesskey="u"><span>Upload file</span></a></li><li id="t-specialpages" class="mw-list-item"><a href="/wiki/Special:SpecialPages" title="A list of all special pages [q]" accesskey="q"><span>Special pages</span></a></li><li id="t-permalink" class="mw-list-item"><a href="/w/index.php?title=Box%E2%80%93Muller_transform&amp;oldid=1184897234" title="Permanent link to this revision of this page"><span>Permanent link</span></a></li><li id="t-info" class="mw-list-item"><a href="/w/index.php?title=Box%E2%80%93Muller_transform&amp;action=info" title="More information about this page"><span>Page information</span></a></li><li id="t-cite" class="mw-list-item"><a href="/w/index.php?title=Special:CiteThisPage&amp;page=Box%E2%80%93Muller_transform&amp;id=1184897234&amp;wpFormIdentifier=titleform" title="Information on how to cite this page"><span>Cite this page</span></a></li><li id="t-urlshortener" class="mw-list-item"><a href="/w/index.php?title=Special:UrlShortener&amp;url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FBox%25E2%2580%2593Muller_transform"><span>Get shortened URL</span></a></li><li id="t-wikibase" class="mw-list-item"><a href="https://www.wikidata.org/wiki/Special:EntityPage/Q895514" title="Structured data on this page hosted by Wikidata [g]" accesskey="g"><span>Wikidata item</span></a></li>
</ul>
</div>
</div>
<div id="p-coll-print_export" class="vector-menu mw-portlet mw-portlet-coll-print_export" >
<div class="vector-menu-heading">
Print/export
</div>
<div class="vector-menu-content">
<ul class="vector-menu-content-list">
<li id="coll-download-as-rl" class="mw-list-item"><a href="/w/index.php?title=Special:DownloadAsPdf&amp;page=Box%E2%80%93Muller_transform&amp;action=show-download-screen" title="Download this page as a PDF file"><span>Download as PDF</span></a></li><li id="t-print" class="mw-list-item"><a href="/w/index.php?title=Box%E2%80%93Muller_transform&amp;printable=yes" title="Printable version of this page [p]" accesskey="p"><span>Printable version</span></a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</nav>
</div>
</div>
</div>
<div class="vector-column-end">
<nav class="vector-page-tools-landmark vector-sticky-pinned-container" aria-label="Page tools">
<div id="vector-page-tools-pinned-container" class="vector-pinned-container">
</div>
</nav>
</div>
<div id="bodyContent" class="vector-body" aria-labelledby="firstHeading" data-mw-ve-target-container>
<div class="vector-body-before-content">
<div class="mw-indicators">
</div>
<div id="siteSub" class="noprint">From Wikipedia, the free encyclopedia</div>
</div>
<div id="contentSub"><div id="mw-content-subtitle"></div></div>
<div id="mw-content-text" class="mw-body-content"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><div class="shortdescription nomobile noexcerpt noprint searchaux" style="display:none">Statistical transform</div>
<figure typeof="mw:File/Thumb"><a href="/wiki/File:Box-Muller_transform_visualisation.svg" class="mw-file-description"><img src="//upload.wikimedia.org/wikipedia/commons/thumb/1/1f/Box-Muller_transform_visualisation.svg/300px-Box-Muller_transform_visualisation.svg.png" decoding="async" width="300" height="300" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/1/1f/Box-Muller_transform_visualisation.svg/450px-Box-Muller_transform_visualisation.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/1/1f/Box-Muller_transform_visualisation.svg/600px-Box-Muller_transform_visualisation.svg.png 2x" data-file-width="512" data-file-height="512" /></a><figcaption>Visualisation of the BoxMuller transform — the coloured points in the unit square (u1, u2), drawn as circles, are mapped to a 2D Gaussian (z0, z1), drawn as crosses. The plots at the margins are the probability distribution functions of z0 and z1. z0 and z1 are unbounded; they appear to be in [-2.5,2.5] due to the choice of the illustrated points. In <a class="external text" href="https://upload.wikimedia.org/wikipedia/commons/1/1f/Box-Muller_transform_visualisation.svg">the SVG file</a>, hover over a point to highlight it and its corresponding point.</figcaption></figure>
<p>The <b>BoxMuller transform</b>, by <a href="/wiki/George_E._P._Box" title="George E. P. Box">George Edward Pelham Box</a> and <a href="/wiki/Mervin_Edgar_Muller" class="mw-redirect" title="Mervin Edgar Muller">Mervin Edgar Muller</a>,<sup id="cite_ref-1" class="reference"><a href="#cite_note-1">&#91;1&#93;</a></sup> is a <a href="/wiki/Random_number_sampling" class="mw-redirect" title="Random number sampling">random number sampling</a> method for generating pairs of <a href="/wiki/Statistical_independence" class="mw-redirect" title="Statistical independence">independent</a>, standard, <a href="/wiki/Normal_distribution" title="Normal distribution">normally distributed</a> (zero <a href="/wiki/Expected_value" title="Expected value">expectation</a>, unit <a href="/wiki/Variance" title="Variance">variance</a>) random numbers, given a source of <a href="/wiki/Uniform_distribution_(continuous)" class="mw-redirect" title="Uniform distribution (continuous)">uniformly distributed</a> random numbers. The method was in fact first mentioned explicitly by <a href="/wiki/Raymond_Paley" title="Raymond Paley">Raymond E. A. C. Paley</a> and <a href="/wiki/Norbert_Wiener" title="Norbert Wiener">Norbert Wiener</a> in 1934.<sup id="cite_ref-2" class="reference"><a href="#cite_note-2">&#91;2&#93;</a></sup>
</p><p>The BoxMuller transform is commonly expressed in two forms. The basic form as given by Box and Muller takes two samples from the uniform distribution on the interval [0,&#160;1] and maps them to two standard, normally distributed samples. The polar form takes two samples from a different interval, [1,&#160;+1], and maps them to two normally distributed samples without the use of sine or cosine functions.
</p><p>The BoxMuller transform was developed as a more computationally efficient alternative to the <a href="/wiki/Inverse_transform_sampling_method" class="mw-redirect" title="Inverse transform sampling method">inverse transform sampling method</a>.<sup id="cite_ref-3" class="reference"><a href="#cite_note-3">&#91;3&#93;</a></sup> The <a href="/wiki/Ziggurat_algorithm" title="Ziggurat algorithm">ziggurat algorithm</a> gives a more efficient method for scalar processors (e.g. old CPUs), while the BoxMuller transform is superior for processors with vector units (e.g. GPUs or modern CPUs).<sup id="cite_ref-4" class="reference"><a href="#cite_note-4">&#91;4&#93;</a></sup>
</p>
<meta property="mw:PageProp/toc" />
<h2><span class="mw-headline" id="Basic_form">Basic form</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Box%E2%80%93Muller_transform&amp;action=edit&amp;section=1" title="Edit section: Basic form"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></h2>
<p>Suppose <i>U</i><sub>1</sub> and <i>U</i><sub>2</sub> are independent samples chosen from the uniform distribution on the <a href="/wiki/Interval_(mathematics)" title="Interval (mathematics)">unit interval</a> (0,&#160;1). Let
</p>
<dl><dd><span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle Z_{0}=R\cos(\Theta )={\sqrt {-2\ln U_{1}}}\cos(2\pi U_{2})\,}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>Z</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>0</mn>
</mrow>
</msub>
<mo>=</mo>
<mi>R</mi>
<mi>cos</mi>
<mo>&#x2061;<!-- --></mo>
<mo stretchy="false">(</mo>
<mi mathvariant="normal">&#x0398;<!-- Θ --></mi>
<mo stretchy="false">)</mo>
<mo>=</mo>
<mrow class="MJX-TeXAtom-ORD">
<msqrt>
<mo>&#x2212;<!-- --></mo>
<mn>2</mn>
<mi>ln</mi>
<mo>&#x2061;<!-- --></mo>
<msub>
<mi>U</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
</msqrt>
</mrow>
<mi>cos</mi>
<mo>&#x2061;<!-- --></mo>
<mo stretchy="false">(</mo>
<mn>2</mn>
<mi>&#x03C0;<!-- π --></mi>
<msub>
<mi>U</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msub>
<mo stretchy="false">)</mo>
<mspace width="thinmathspace" />
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle Z_{0}=R\cos(\Theta )={\sqrt {-2\ln U_{1}}}\cos(2\pi U_{2})\,}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/46e09d833afb2466f517e90dbc0e363cb0bcdf8a" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -1.005ex; width:39.199ex; height:3.343ex;" alt="Z_0 = R \cos(\Theta) =\sqrt{-2 \ln U_1} \cos(2 \pi U_2)\,"></span></dd></dl>
<p>and
</p>
<dl><dd><span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle Z_{1}=R\sin(\Theta )={\sqrt {-2\ln U_{1}}}\sin(2\pi U_{2}).\,}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>Z</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
<mo>=</mo>
<mi>R</mi>
<mi>sin</mi>
<mo>&#x2061;<!-- --></mo>
<mo stretchy="false">(</mo>
<mi mathvariant="normal">&#x0398;<!-- Θ --></mi>
<mo stretchy="false">)</mo>
<mo>=</mo>
<mrow class="MJX-TeXAtom-ORD">
<msqrt>
<mo>&#x2212;<!-- --></mo>
<mn>2</mn>
<mi>ln</mi>
<mo>&#x2061;<!-- --></mo>
<msub>
<mi>U</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
</msqrt>
</mrow>
<mi>sin</mi>
<mo>&#x2061;<!-- --></mo>
<mo stretchy="false">(</mo>
<mn>2</mn>
<mi>&#x03C0;<!-- π --></mi>
<msub>
<mi>U</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msub>
<mo stretchy="false">)</mo>
<mo>.</mo>
<mspace width="thinmathspace" />
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle Z_{1}=R\sin(\Theta )={\sqrt {-2\ln U_{1}}}\sin(2\pi U_{2}).\,}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/5c1ef74f02625a0a670e7c7668e990d8446f8fde" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -1.005ex; width:39.335ex; height:3.343ex;" alt="Z_1 = R \sin(\Theta) = \sqrt{-2 \ln U_1} \sin(2 \pi U_2).\,"></span></dd></dl>
<p>Then <i>Z</i><sub>0</sub> and <i>Z</i><sub>1</sub> are <a href="/wiki/Statistical_independence" class="mw-redirect" title="Statistical independence">independent</a> random variables with a <a href="/wiki/Standard_normal_distribution" class="mw-redirect" title="Standard normal distribution">standard normal distribution</a>.
</p><p>The derivation<sup id="cite_ref-5" class="reference"><a href="#cite_note-5">&#91;5&#93;</a></sup> is based on a property of a two-dimensional <a href="/wiki/Cartesian_coordinate_system" title="Cartesian coordinate system">Cartesian system</a>, where X and Y coordinates are described by two independent and normally distributed random variables, the random variables for <i>R</i><sup>2</sup> and Θ (shown above) in the corresponding polar coordinates are also independent and can be expressed as
</p>
<dl><dd><span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle R^{2}=-2\cdot \ln U_{1}\,}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msup>
<mi>R</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
<mo>=</mo>
<mo>&#x2212;<!-- --></mo>
<mn>2</mn>
<mo>&#x22C5;<!-- ⋅ --></mo>
<mi>ln</mi>
<mo>&#x2061;<!-- --></mo>
<msub>
<mi>U</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
<mspace width="thinmathspace" />
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle R^{2}=-2\cdot \ln U_{1}\,}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/702928cf2d25505446185f796a9dcfa0f0d5034b" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:15.922ex; height:3.009ex;" alt="R^2 = -2\cdot\ln U_1\,"></span></dd></dl>
<p>and
</p>
<dl><dd><span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \Theta =2\pi U_{2}.\,}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi mathvariant="normal">&#x0398;<!-- Θ --></mi>
<mo>=</mo>
<mn>2</mn>
<mi>&#x03C0;<!-- π --></mi>
<msub>
<mi>U</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msub>
<mo>.</mo>
<mspace width="thinmathspace" />
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \Theta =2\pi U_{2}.\,}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/145ac177710afd925efaae9ae8ba6c594b35b20b" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:11.077ex; height:2.509ex;" alt="\Theta = 2\pi U_2. \,"></span></dd></dl>
<p>Because <i>R</i><sup>2</sup> is the square of the norm of the standard <a href="/wiki/Bivariate_normal" class="mw-redirect" title="Bivariate normal">bivariate normal</a> variable (<i>X</i>,&#160;<i>Y</i>), it has the <a href="/wiki/Chi-squared_distribution" title="Chi-squared distribution">chi-squared distribution</a> with two degrees of freedom. In the special case of two degrees of freedom, the chi-squared distribution coincides with the <a href="/wiki/Exponential_distribution" title="Exponential distribution">exponential distribution</a>, and the equation for <i>R</i><sup>2</sup> above is a simple way of generating the required exponential variate.
</p>
<h2><span class="mw-headline" id="Polar_form">Polar form</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Box%E2%80%93Muller_transform&amp;action=edit&amp;section=2" title="Edit section: Polar form"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></h2>
<style data-mw-deduplicate="TemplateStyles:r1033289096">.mw-parser-output .hatnote{font-style:italic}.mw-parser-output div.hatnote{padding-left:1.6em;margin-bottom:0.5em}.mw-parser-output .hatnote i{font-style:normal}.mw-parser-output .hatnote+link+.hatnote{margin-top:-0.5em}</style><div role="note" class="hatnote navigation-not-searchable">Main article: <a href="/wiki/Marsaglia_polar_method" title="Marsaglia polar method">Marsaglia polar method</a></div>
<figure typeof="mw:File/Thumb"><a href="/wiki/File:BoxMullerTransformUsingPolarCoordinates.png" class="mw-file-description"><img src="//upload.wikimedia.org/wikipedia/commons/thumb/d/d4/BoxMullerTransformUsingPolarCoordinates.png/400px-BoxMullerTransformUsingPolarCoordinates.png" decoding="async" width="400" height="251" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/d/d4/BoxMullerTransformUsingPolarCoordinates.png/600px-BoxMullerTransformUsingPolarCoordinates.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/d/d4/BoxMullerTransformUsingPolarCoordinates.png/800px-BoxMullerTransformUsingPolarCoordinates.png 2x" data-file-width="1007" data-file-height="632" /></a><figcaption>Two uniformly distributed values, <i>u</i> and <i>v</i> are used to produce the value <span class="nowrap"><i>s</i> = <i>R</i><sup>2</sup></span>, which is likewise uniformly distributed. The definitions of the sine and cosine are then applied to the basic form of the BoxMuller transform to avoid using trigonometric functions.</figcaption></figure><p> The polar form was first proposed by J. Bell<sup id="cite_ref-Bell68_6-0" class="reference"><a href="#cite_note-Bell68-6">&#91;6&#93;</a></sup> and then modified by R. Knop.<sup id="cite_ref-7" class="reference"><a href="#cite_note-7">&#91;7&#93;</a></sup> While several different versions of the polar method have been described, the version of R. Knop will be described here because it is the most widely used, in part due to its inclusion in <i><a href="/wiki/Numerical_Recipes" title="Numerical Recipes">Numerical Recipes</a></i>. A slightly different form is described as "Algorithm P" by D. Knuth in <i><a href="/wiki/The_Art_of_Computer_Programming" title="The Art of Computer Programming">The Art of Computer Programming</a></i>.<sup id="cite_ref-8" class="reference"><a href="#cite_note-8">&#91;8&#93;</a></sup>
</p><p>Given <i>u</i> and <i>v</i>, independent and uniformly distributed in the closed interval [1,&#160;+1], set <span class="nowrap"><i>s</i> = <i>R</i><sup>2</sup> = <i>u</i><sup>2</sup> + <i>v</i><sup>2</sup></span>. If <span class="nowrap"><i>s</i> = 0</span> or <span class="nowrap"><i>s</i> ≥ 1</span>, discard <i>u</i> and <i>v</i>, and try another pair (<i>u</i>,&#160;<i>v</i>). Because <i>u</i> and <i>v</i> are uniformly distributed and because only points within the unit circle have been admitted, the values of <i>s</i> will be uniformly distributed in the open interval (0,&#160;1), too. The latter can be seen by calculating the cumulative distribution function for <i>s</i> in the interval (0,&#160;1). This is the area of a circle with radius <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \scriptstyle {\sqrt {s}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mstyle displaystyle="false" scriptlevel="1">
<mrow class="MJX-TeXAtom-ORD">
<msqrt>
<mi>s</mi>
</msqrt>
</mrow>
</mstyle>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \scriptstyle {\sqrt {s}}}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a41099430a8cc26566c1c11a5155f2cedcf2fc7c" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:2.14ex; height:2.176ex;" alt="\scriptstyle \sqrt{s}"></span>, divided by <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \scriptstyle \pi }">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mstyle displaystyle="false" scriptlevel="1">
<mi>&#x03C0;<!-- π --></mi>
</mstyle>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \scriptstyle \pi }</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/bb2635a9b35ac9dfcc9fed1229d49f5355bd3a8d" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:0.942ex; height:1.343ex;" alt="\scriptstyle\pi"></span>. From this we find the probability density function to have the constant value 1 on the interval (0,&#160;1). Equally so, the angle θ divided by <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \scriptstyle 2\pi }">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mstyle displaystyle="false" scriptlevel="1">
<mn>2</mn>
<mi>&#x03C0;<!-- π --></mi>
</mstyle>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \scriptstyle 2\pi }</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ca1c97b2aba7cb514f08126df3889034ba5927b4" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.764ex; height:1.676ex;" alt="\scriptstyle 2 \pi"></span> is uniformly distributed in the interval [0,&#160;1) and independent of <i>s</i>.
</p><p>We now identify the value of <i>s</i> with that of <i>U</i><sub>1</sub> and <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \scriptstyle \theta /(2\pi )}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mstyle displaystyle="false" scriptlevel="1">
<mi>&#x03B8;<!-- θ --></mi>
<mrow class="MJX-TeXAtom-ORD">
<mo>/</mo>
</mrow>
<mo stretchy="false">(</mo>
<mn>2</mn>
<mi>&#x03C0;<!-- π --></mi>
<mo stretchy="false">)</mo>
</mstyle>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \scriptstyle \theta /(2\pi )}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/98067e94723827cfc412f06eb4b506afe83bc185" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:4.636ex; height:2.176ex;" alt="\scriptstyle \theta/(2 \pi)"></span> with that of <i>U</i><sub>2</sub> in the basic form. As shown in the figure, the values of <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \scriptstyle \cos \theta =\cos 2\pi U_{2}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mstyle displaystyle="false" scriptlevel="1">
<mi>cos</mi>
<mo>&#x2061;<!-- --></mo>
<mi>&#x03B8;<!-- θ --></mi>
<mo>=</mo>
<mi>cos</mi>
<mo>&#x2061;<!-- --></mo>
<mn>2</mn>
<mi>&#x03C0;<!-- π --></mi>
<msub>
<mi>U</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msub>
</mstyle>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \scriptstyle \cos \theta =\cos 2\pi U_{2}}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/8454069b95bf2685b26b9e597caa3e2e267a55e2" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:10.942ex; height:1.843ex;" alt="\scriptstyle \cos \theta = \cos 2 \pi U_2"></span> and <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \scriptstyle \sin \theta =\sin 2\pi U_{2}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mstyle displaystyle="false" scriptlevel="1">
<mi>sin</mi>
<mo>&#x2061;<!-- --></mo>
<mi>&#x03B8;<!-- θ --></mi>
<mo>=</mo>
<mi>sin</mi>
<mo>&#x2061;<!-- --></mo>
<mn>2</mn>
<mi>&#x03C0;<!-- π --></mi>
<msub>
<mi>U</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msub>
</mstyle>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \scriptstyle \sin \theta =\sin 2\pi U_{2}}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/d64a13bcc01da7101303eca350fe5a53564858d6" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:10.58ex; height:1.843ex;" alt="\scriptstyle \sin \theta = \sin 2 \pi U_2"></span> in the basic form can be replaced with the ratios <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \scriptstyle \cos \theta =u/R=u/{\sqrt {s}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mstyle displaystyle="false" scriptlevel="1">
<mi>cos</mi>
<mo>&#x2061;<!-- --></mo>
<mi>&#x03B8;<!-- θ --></mi>
<mo>=</mo>
<mi>u</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo>/</mo>
</mrow>
<mi>R</mi>
<mo>=</mo>
<mi>u</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo>/</mo>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<msqrt>
<mi>s</mi>
</msqrt>
</mrow>
</mstyle>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \scriptstyle \cos \theta =u/R=u/{\sqrt {s}}}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/5375f4c6b1ba089ebccbabfb7765ea28c1de0383" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:12.827ex; height:2.176ex;" alt="\scriptstyle\cos \theta = u/R = u/\sqrt{s}"></span> and <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \scriptstyle \sin \theta =v/R=v/{\sqrt {s}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mstyle displaystyle="false" scriptlevel="1">
<mi>sin</mi>
<mo>&#x2061;<!-- --></mo>
<mi>&#x03B8;<!-- θ --></mi>
<mo>=</mo>
<mi>v</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo>/</mo>
</mrow>
<mi>R</mi>
<mo>=</mo>
<mi>v</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo>/</mo>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<msqrt>
<mi>s</mi>
</msqrt>
</mrow>
</mstyle>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \scriptstyle \sin \theta =v/R=v/{\sqrt {s}}}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/c6190ca5e4c906826786c8ce696ea3b9ca11aefa" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:12.36ex; height:2.176ex;" alt="\scriptstyle\sin \theta = v/R = v/\sqrt{s}"></span>, respectively. The advantage is that calculating the trigonometric functions directly can be avoided. This is helpful when trigonometric functions are more expensive to compute than the single division that replaces each one.
</p><p>Just as the basic form produces two standard normal deviates, so does this alternate calculation.
</p>
<dl><dd><span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle z_{0}={\sqrt {-2\ln U_{1}}}\cos(2\pi U_{2})={\sqrt {-2\ln s}}\left({\frac {u}{\sqrt {s}}}\right)=u\cdot {\sqrt {\frac {-2\ln s}{s}}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>z</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>0</mn>
</mrow>
</msub>
<mo>=</mo>
<mrow class="MJX-TeXAtom-ORD">
<msqrt>
<mo>&#x2212;<!-- --></mo>
<mn>2</mn>
<mi>ln</mi>
<mo>&#x2061;<!-- --></mo>
<msub>
<mi>U</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
</msqrt>
</mrow>
<mi>cos</mi>
<mo>&#x2061;<!-- --></mo>
<mo stretchy="false">(</mo>
<mn>2</mn>
<mi>&#x03C0;<!-- π --></mi>
<msub>
<mi>U</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msub>
<mo stretchy="false">)</mo>
<mo>=</mo>
<mrow class="MJX-TeXAtom-ORD">
<msqrt>
<mo>&#x2212;<!-- --></mo>
<mn>2</mn>
<mi>ln</mi>
<mo>&#x2061;<!-- --></mo>
<mi>s</mi>
</msqrt>
</mrow>
<mrow>
<mo>(</mo>
<mrow class="MJX-TeXAtom-ORD">
<mfrac>
<mi>u</mi>
<msqrt>
<mi>s</mi>
</msqrt>
</mfrac>
</mrow>
<mo>)</mo>
</mrow>
<mo>=</mo>
<mi>u</mi>
<mo>&#x22C5;<!-- ⋅ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<msqrt>
<mfrac>
<mrow>
<mo>&#x2212;<!-- --></mo>
<mn>2</mn>
<mi>ln</mi>
<mo>&#x2061;<!-- --></mo>
<mi>s</mi>
</mrow>
<mi>s</mi>
</mfrac>
</msqrt>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle z_{0}={\sqrt {-2\ln U_{1}}}\cos(2\pi U_{2})={\sqrt {-2\ln s}}\left({\frac {u}{\sqrt {s}}}\right)=u\cdot {\sqrt {\frac {-2\ln s}{s}}}}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/e40643ede00b3902399f6ec449eed868a7edb734" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -2.838ex; width:61.849ex; height:6.676ex;" alt="z_0 = \sqrt{-2 \ln U_1} \cos(2 \pi U_2) = \sqrt{-2 \ln s} \left(\frac{u}{\sqrt{s}}\right) = u \cdot \sqrt{\frac{-2 \ln s}{s}}"></span></dd></dl>
<p>and
</p>
<dl><dd><span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle z_{1}={\sqrt {-2\ln U_{1}}}\sin(2\pi U_{2})={\sqrt {-2\ln s}}\left({\frac {v}{\sqrt {s}}}\right)=v\cdot {\sqrt {\frac {-2\ln s}{s}}}.}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>z</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
<mo>=</mo>
<mrow class="MJX-TeXAtom-ORD">
<msqrt>
<mo>&#x2212;<!-- --></mo>
<mn>2</mn>
<mi>ln</mi>
<mo>&#x2061;<!-- --></mo>
<msub>
<mi>U</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
</msqrt>
</mrow>
<mi>sin</mi>
<mo>&#x2061;<!-- --></mo>
<mo stretchy="false">(</mo>
<mn>2</mn>
<mi>&#x03C0;<!-- π --></mi>
<msub>
<mi>U</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msub>
<mo stretchy="false">)</mo>
<mo>=</mo>
<mrow class="MJX-TeXAtom-ORD">
<msqrt>
<mo>&#x2212;<!-- --></mo>
<mn>2</mn>
<mi>ln</mi>
<mo>&#x2061;<!-- --></mo>
<mi>s</mi>
</msqrt>
</mrow>
<mrow>
<mo>(</mo>
<mrow class="MJX-TeXAtom-ORD">
<mfrac>
<mi>v</mi>
<msqrt>
<mi>s</mi>
</msqrt>
</mfrac>
</mrow>
<mo>)</mo>
</mrow>
<mo>=</mo>
<mi>v</mi>
<mo>&#x22C5;<!-- ⋅ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<msqrt>
<mfrac>
<mrow>
<mo>&#x2212;<!-- --></mo>
<mn>2</mn>
<mi>ln</mi>
<mo>&#x2061;<!-- --></mo>
<mi>s</mi>
</mrow>
<mi>s</mi>
</mfrac>
</msqrt>
</mrow>
<mo>.</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle z_{1}={\sqrt {-2\ln U_{1}}}\sin(2\pi U_{2})={\sqrt {-2\ln s}}\left({\frac {v}{\sqrt {s}}}\right)=v\cdot {\sqrt {\frac {-2\ln s}{s}}}.}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/5c7c0d13474cc0cdf0b4893a2ad8595f8b51d852" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -2.838ex; width:62.038ex; height:6.676ex;" alt="z_1 = \sqrt{-2 \ln U_1} \sin(2 \pi U_2) = \sqrt{-2 \ln s}\left( \frac{v}{\sqrt{s}}\right) = v \cdot \sqrt{\frac{-2 \ln s}{s}}."></span></dd></dl>
<h2><span class="mw-headline" id="Contrasting_the_two_forms">Contrasting the two forms</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Box%E2%80%93Muller_transform&amp;action=edit&amp;section=3" title="Edit section: Contrasting the two forms"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></h2>
<p>The polar method differs from the basic method in that it is a type of <a href="/wiki/Rejection_sampling" title="Rejection sampling">rejection sampling</a>. It discards some generated random numbers, but can be faster than the basic method because it is simpler to compute (provided that the random number generator is relatively fast) and is more numerically robust.<sup id="cite_ref-Carter_9-0" class="reference"><a href="#cite_note-Carter-9">&#91;9&#93;</a></sup> Avoiding the use of expensive trigonometric functions improves speed over the basic form.<sup id="cite_ref-Bell68_6-1" class="reference"><a href="#cite_note-Bell68-6">&#91;6&#93;</a></sup> It discards <span class="nowrap">1 <span class="texhtml mvar" style="font-style:italic;">π</span>/4 ≈ 21.46%</span> of the total input uniformly distributed random number pairs generated, i.e. discards <span class="nowrap">4/<span class="texhtml mvar" style="font-style:italic;">π</span> 1 ≈ 27.32%</span> uniformly distributed random number pairs per <a href="/wiki/Normal_distribution" title="Normal distribution">Gaussian</a> random number pair generated, requiring <span class="nowrap">4/<span class="texhtml mvar" style="font-style:italic;">π</span> ≈ 1.2732</span> input random numbers per output random number.
</p><p>The basic form requires two multiplications, 1/2 logarithm, 1/2 square root, and one trigonometric function for each normal variate.<sup id="cite_ref-10" class="reference"><a href="#cite_note-10">&#91;10&#93;</a></sup> On some processors, the cosine and sine of the same argument can be calculated in parallel using a single instruction. Notably for Intel-based machines, one can use the fsincos assembler instruction or the expi instruction (usually available from C as an <a href="/wiki/Intrinsic_function" title="Intrinsic function">intrinsic function</a>), to calculate complex
</p>
<dl><dd><span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \exp(iz)=e^{iz}=\cos z+i\sin z,\,}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>exp</mi>
<mo>&#x2061;<!-- --></mo>
<mo stretchy="false">(</mo>
<mi>i</mi>
<mi>z</mi>
<mo stretchy="false">)</mo>
<mo>=</mo>
<msup>
<mi>e</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>i</mi>
<mi>z</mi>
</mrow>
</msup>
<mo>=</mo>
<mi>cos</mi>
<mo>&#x2061;<!-- --></mo>
<mi>z</mi>
<mo>+</mo>
<mi>i</mi>
<mi>sin</mi>
<mo>&#x2061;<!-- --></mo>
<mi>z</mi>
<mo>,</mo>
<mspace width="thinmathspace" />
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \exp(iz)=e^{iz}=\cos z+i\sin z,\,}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/155b08d9d1897e1de951c73317a5b44ad488131d" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:30.083ex; height:3.176ex;" alt="{\displaystyle \exp(iz)=e^{iz}=\cos z+i\sin z,\,}"></span></dd></dl>
<p>and just separate the real and imaginary parts.
</p><p><b>Note:</b>
To explicitly calculate the complex-polar form use the following substitutions in the general form,
</p><p>Let <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle r={\sqrt {-\ln(u_{1})}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>r</mi>
<mo>=</mo>
<mrow class="MJX-TeXAtom-ORD">
<msqrt>
<mo>&#x2212;<!-- --></mo>
<mi>ln</mi>
<mo>&#x2061;<!-- --></mo>
<mo stretchy="false">(</mo>
<msub>
<mi>u</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
<mo stretchy="false">)</mo>
</msqrt>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle r={\sqrt {-\ln(u_{1})}}}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/5a9257650a4e53b6ffb5368b15d5713dddf2005e" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -1.838ex; width:14.799ex; height:4.843ex;" alt="{\displaystyle r={\sqrt {-\ln(u_{1})}}}"></span> and <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle z=2\pi u_{2}.}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>z</mi>
<mo>=</mo>
<mn>2</mn>
<mi>&#x03C0;<!-- π --></mi>
<msub>
<mi>u</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msub>
<mo>.</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle z=2\pi u_{2}.}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/e2b786079f38d943357a77df48ba50f0244dd91d" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:9.712ex; height:2.509ex;" alt="{\displaystyle z=2\pi u_{2}.}"></span> Then
</p>
<dl><dd><span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle re^{iz}={\sqrt {-\ln(u_{1})}}e^{i2\pi u_{2}}={\sqrt {-2\ln(u_{1})}}\left[\cos(2\pi u_{2})+i\sin(2\pi u_{2})\right].}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>r</mi>
<msup>
<mi>e</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>i</mi>
<mi>z</mi>
</mrow>
</msup>
<mo>=</mo>
<mrow class="MJX-TeXAtom-ORD">
<msqrt>
<mo>&#x2212;<!-- --></mo>
<mi>ln</mi>
<mo>&#x2061;<!-- --></mo>
<mo stretchy="false">(</mo>
<msub>
<mi>u</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
<mo stretchy="false">)</mo>
</msqrt>
</mrow>
<msup>
<mi>e</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>i</mi>
<mn>2</mn>
<mi>&#x03C0;<!-- π --></mi>
<msub>
<mi>u</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msub>
</mrow>
</msup>
<mo>=</mo>
<mrow class="MJX-TeXAtom-ORD">
<msqrt>
<mo>&#x2212;<!-- --></mo>
<mn>2</mn>
<mi>ln</mi>
<mo>&#x2061;<!-- --></mo>
<mo stretchy="false">(</mo>
<msub>
<mi>u</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
<mo stretchy="false">)</mo>
</msqrt>
</mrow>
<mrow>
<mo>[</mo>
<mrow>
<mi>cos</mi>
<mo>&#x2061;<!-- --></mo>
<mo stretchy="false">(</mo>
<mn>2</mn>
<mi>&#x03C0;<!-- π --></mi>
<msub>
<mi>u</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msub>
<mo stretchy="false">)</mo>
<mo>+</mo>
<mi>i</mi>
<mi>sin</mi>
<mo>&#x2061;<!-- --></mo>
<mo stretchy="false">(</mo>
<mn>2</mn>
<mi>&#x03C0;<!-- π --></mi>
<msub>
<mi>u</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msub>
<mo stretchy="false">)</mo>
</mrow>
<mo>]</mo>
</mrow>
<mo>.</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle re^{iz}={\sqrt {-\ln(u_{1})}}e^{i2\pi u_{2}}={\sqrt {-2\ln(u_{1})}}\left[\cos(2\pi u_{2})+i\sin(2\pi u_{2})\right].}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/cde981cf6a8d8e6c83066f1c68f3f40804b9ece6" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -1.838ex; width:63.869ex; height:4.843ex;" alt="{\displaystyle re^{iz}={\sqrt {-\ln(u_{1})}}e^{i2\pi u_{2}}={\sqrt {-2\ln(u_{1})}}\left[\cos(2\pi u_{2})+i\sin(2\pi u_{2})\right].}"></span></dd></dl>
<p>The polar form requires 3/2 multiplications, 1/2 logarithm, 1/2 square root, and 1/2 division for each normal variate. The effect is to replace one multiplication and one trigonometric function with a single division and a conditional loop.
</p>
<h2><span class="mw-headline" id="Tails_truncation">Tails truncation</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Box%E2%80%93Muller_transform&amp;action=edit&amp;section=4" title="Edit section: Tails truncation"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></h2>
<p>When a computer is used to produce a uniform random variable it will inevitably have some inaccuracies because there is a lower bound on how close numbers can be to 0. If the generator uses 32 bits per output value, the smallest non-zero number that can be generated is <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle 2^{-32}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msup>
<mn>2</mn>
<mrow class="MJX-TeXAtom-ORD">
<mo>&#x2212;<!-- --></mo>
<mn>32</mn>
</mrow>
</msup>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle 2^{-32}}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/f6c5244b1622127f7f8009d261fca9759696ce5c" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:4.317ex; height:2.676ex;" alt="2^{-32}"></span>. When <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle U_{1}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>U</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle U_{1}}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/bc9e7f892894bc50c32ce1b9f9a68a15562146ac" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:2.642ex; height:2.509ex;" alt="U_{1}"></span> and <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle U_{2}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>U</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle U_{2}}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/590fa6a550fbe2866a28243a733d54245d218b9d" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:2.642ex; height:2.509ex;" alt="U_{2}"></span> are equal to this the BoxMuller transform produces a normal random deviate equal to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \delta ={\sqrt {-2\ln(2^{-32})}}\cos(2\pi 2^{-32})\approx 6.660}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>&#x03B4;<!-- δ --></mi>
<mo>=</mo>
<mrow class="MJX-TeXAtom-ORD">
<msqrt>
<mo>&#x2212;<!-- --></mo>
<mn>2</mn>
<mi>ln</mi>
<mo>&#x2061;<!-- --></mo>
<mo stretchy="false">(</mo>
<msup>
<mn>2</mn>
<mrow class="MJX-TeXAtom-ORD">
<mo>&#x2212;<!-- --></mo>
<mn>32</mn>
</mrow>
</msup>
<mo stretchy="false">)</mo>
</msqrt>
</mrow>
<mi>cos</mi>
<mo>&#x2061;<!-- --></mo>
<mo stretchy="false">(</mo>
<mn>2</mn>
<mi>&#x03C0;<!-- π --></mi>
<msup>
<mn>2</mn>
<mrow class="MJX-TeXAtom-ORD">
<mo>&#x2212;<!-- --></mo>
<mn>32</mn>
</mrow>
</msup>
<mo stretchy="false">)</mo>
<mo>&#x2248;<!-- ≈ --></mo>
<mn>6.660</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \delta ={\sqrt {-2\ln(2^{-32})}}\cos(2\pi 2^{-32})\approx 6.660}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/30814f8ae2ee8bd162765625874be9c2d33f9ef0" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -1.671ex; width:38.409ex; height:4.843ex;" alt="{\displaystyle \delta ={\sqrt {-2\ln(2^{-32})}}\cos(2\pi 2^{-32})\approx 6.660}"></span>. This means that the algorithm will not produce random variables more than 6.660 standard deviations from the mean. This corresponds to a proportion of <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle 2(1-\Phi (\delta ))\simeq 2.738\times 10^{-11}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mn>2</mn>
<mo stretchy="false">(</mo>
<mn>1</mn>
<mo>&#x2212;<!-- --></mo>
<mi mathvariant="normal">&#x03A6;<!-- Φ --></mi>
<mo stretchy="false">(</mo>
<mi>&#x03B4;<!-- δ --></mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">)</mo>
<mo>&#x2243;<!-- ≃ --></mo>
<mn>2.738</mn>
<mo>&#x00D7;<!-- × --></mo>
<msup>
<mn>10</mn>
<mrow class="MJX-TeXAtom-ORD">
<mo>&#x2212;<!-- --></mo>
<mn>11</mn>
</mrow>
</msup>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle 2(1-\Phi (\delta ))\simeq 2.738\times 10^{-11}}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/fb7a55c8ee4eab71c470cc46b1979b383dd69aa2" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:28.226ex; height:3.176ex;" alt="{\displaystyle 2(1-\Phi (\delta ))\simeq 2.738\times 10^{-11}}"></span> lost due to the truncation, where <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \Phi (\delta )}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi mathvariant="normal">&#x03A6;<!-- Φ --></mi>
<mo stretchy="false">(</mo>
<mi>&#x03B4;<!-- δ --></mi>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \Phi (\delta )}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/73d36f5d5452ae04596ff3d4d22145599c892478" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:4.536ex; height:2.843ex;" alt="{\displaystyle \Phi (\delta )}"></span> is the standard cumulative normal distribution. With 64 bits the limit is pushed to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \delta =9.419}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>&#x03B4;<!-- δ --></mi>
<mo>=</mo>
<mn>9.419</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \delta =9.419}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/8f742fca42e09bdf8f32968e17f281dd2522a51b" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:9.444ex; height:2.343ex;" alt="{\displaystyle \delta =9.419}"></span> standard deviations, for which <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle 2(1-\Phi (\delta ))&lt;5\times 10^{-21}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mn>2</mn>
<mo stretchy="false">(</mo>
<mn>1</mn>
<mo>&#x2212;<!-- --></mo>
<mi mathvariant="normal">&#x03A6;<!-- Φ --></mi>
<mo stretchy="false">(</mo>
<mi>&#x03B4;<!-- δ --></mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">)</mo>
<mo>&lt;</mo>
<mn>5</mn>
<mo>&#x00D7;<!-- × --></mo>
<msup>
<mn>10</mn>
<mrow class="MJX-TeXAtom-ORD">
<mo>&#x2212;<!-- --></mo>
<mn>21</mn>
</mrow>
</msup>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle 2(1-\Phi (\delta ))&lt;5\times 10^{-21}}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ddf8782d5f1f7bc7ebf99e4fa8e976e2c617e4f1" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:24.092ex; height:3.176ex;" alt="{\displaystyle 2(1-\Phi (\delta ))&lt;5\times 10^{-21}}"></span>.
</p>
<h2><span class="mw-headline" id="Implementation">Implementation</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Box%E2%80%93Muller_transform&amp;action=edit&amp;section=5" title="Edit section: Implementation"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></h2>
<p>The standard BoxMuller transform generates values from the standard normal distribution (<i>i.e.</i> <a href="/wiki/Standard_normal_deviate" title="Standard normal deviate">standard normal deviates</a>) with mean <i>0</i> and standard deviation <i>1</i>. The implementation below in standard <a href="/wiki/C%2B%2B" title="C++">C++</a> generates values from any normal distribution with mean <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \mu }">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>&#x03BC;<!-- μ --></mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \mu }</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/9fd47b2a39f7a7856952afec1f1db72c67af6161" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:1.402ex; height:2.176ex;" alt="\mu "></span> and variance <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \sigma ^{2}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msup>
<mi>&#x03C3;<!-- σ --></mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \sigma ^{2}}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/53a5c55e536acf250c1d3e0f754be5692b843ef5" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.385ex; height:2.676ex;" alt="\sigma ^{2}"></span>. If <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle Z}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>Z</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle Z}</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/1cc6b75e09a8aa3f04d8584b11db534f88fb56bd" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.68ex; height:2.176ex;" alt="Z"></span> is a standard normal deviate, then <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle X=Z\sigma +\mu }">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>X</mi>
<mo>=</mo>
<mi>Z</mi>
<mi>&#x03C3;<!-- σ --></mi>
<mo>+</mo>
<mi>&#x03BC;<!-- μ --></mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle X=Z\sigma +\mu }</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/cce5cc456b46bf59dc2c6374a2cc30f0246e1a5e" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:12.331ex; height:2.676ex;" alt="X=Z\sigma +\mu "></span> will have a normal distribution with mean <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \mu }">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>&#x03BC;<!-- μ --></mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \mu }</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/9fd47b2a39f7a7856952afec1f1db72c67af6161" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:1.402ex; height:2.176ex;" alt="\mu "></span> and standard deviation <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \sigma }">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>&#x03C3;<!-- σ --></mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \sigma }</annotation>
</semantics>
</math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/59f59b7c3e6fdb1d0365a494b81fb9a696138c36" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.33ex; height:1.676ex;" alt="\sigma "></span>. The random number generator has been <a href="/wiki/Random_seed" title="Random seed">seeded</a> to ensure that new, pseudo-random values will be returned from sequential calls to the <code>generateGaussianNoise</code> function.
</p>
<div class="mw-highlight mw-highlight-lang-cpp mw-content-ltr" dir="ltr"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;cmath&gt;</span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;limits&gt;</span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;random&gt;</span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;utility&gt;</span>
<span class="c1">//&quot;mu&quot; is the mean of the distribution, and &quot;sigma&quot; is the standard deviation.</span>
<span class="n">std</span><span class="o">::</span><span class="n">pair</span><span class="o">&lt;</span><span class="kt">double</span><span class="p">,</span><span class="w"> </span><span class="kt">double</span><span class="o">&gt;</span><span class="w"> </span><span class="n">generateGaussianNoise</span><span class="p">(</span><span class="kt">double</span><span class="w"> </span><span class="n">mu</span><span class="p">,</span><span class="w"> </span><span class="kt">double</span><span class="w"> </span><span class="n">sigma</span><span class="p">)</span>
<span class="p">{</span>
<span class="w"> </span><span class="k">constexpr</span><span class="w"> </span><span class="kt">double</span><span class="w"> </span><span class="n">epsilon</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">numeric_limits</span><span class="o">&lt;</span><span class="kt">double</span><span class="o">&gt;::</span><span class="n">epsilon</span><span class="p">();</span>
<span class="w"> </span><span class="k">constexpr</span><span class="w"> </span><span class="kt">double</span><span class="w"> </span><span class="n">two_pi</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">2.0</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">M_PI</span><span class="p">;</span>
<span class="w"> </span><span class="c1">//initialize the random uniform number generator (runif) in a range 0 to 1</span>
<span class="w"> </span><span class="k">static</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">mt19937</span><span class="w"> </span><span class="nf">rng</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">random_device</span><span class="p">{}());</span><span class="w"> </span><span class="c1">// Standard mersenne_twister_engine seeded with rd()</span>
<span class="w"> </span><span class="k">static</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">uniform_real_distribution</span><span class="o">&lt;&gt;</span><span class="w"> </span><span class="n">runif</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span><span class="w"> </span><span class="mf">1.0</span><span class="p">);</span>
<span class="w"> </span><span class="c1">//create two random numbers, make sure u1 is greater than epsilon</span>
<span class="w"> </span><span class="kt">double</span><span class="w"> </span><span class="n">u1</span><span class="p">,</span><span class="w"> </span><span class="n">u2</span><span class="p">;</span>
<span class="w"> </span><span class="k">do</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">u1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">runif</span><span class="p">(</span><span class="n">rng</span><span class="p">);</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="p">(</span><span class="n">u1</span><span class="w"> </span><span class="o">&lt;=</span><span class="w"> </span><span class="n">epsilon</span><span class="p">);</span>
<span class="w"> </span><span class="n">u2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">runif</span><span class="p">(</span><span class="n">rng</span><span class="p">);</span>
<span class="w"> </span><span class="c1">//compute z0 and z1</span>
<span class="w"> </span><span class="k">auto</span><span class="w"> </span><span class="n">mag</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">sigma</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">sqrt</span><span class="p">(</span><span class="mf">-2.0</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">log</span><span class="p">(</span><span class="n">u1</span><span class="p">));</span>
<span class="w"> </span><span class="k">auto</span><span class="w"> </span><span class="n">z0</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">mag</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">cos</span><span class="p">(</span><span class="n">two_pi</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">u2</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">mu</span><span class="p">;</span>
<span class="w"> </span><span class="k">auto</span><span class="w"> </span><span class="n">z1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">mag</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">sin</span><span class="p">(</span><span class="n">two_pi</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">u2</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">mu</span><span class="p">;</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">make_pair</span><span class="p">(</span><span class="n">z0</span><span class="p">,</span><span class="w"> </span><span class="n">z1</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
<h2><span class="mw-headline" id="See_also">See also</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Box%E2%80%93Muller_transform&amp;action=edit&amp;section=6" title="Edit section: See also"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></h2>
<ul><li><a href="/wiki/Inverse_transform_sampling" title="Inverse transform sampling">Inverse transform sampling</a></li>
<li><a href="/wiki/Marsaglia_polar_method" title="Marsaglia polar method">Marsaglia polar method</a>, similar transform to BoxMuller, which uses Cartesian coordinates, instead of polar coordinates</li></ul>
<h2><span class="mw-headline" id="References">References</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Box%E2%80%93Muller_transform&amp;action=edit&amp;section=7" title="Edit section: References"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></h2>
<ul><li><style data-mw-deduplicate="TemplateStyles:r1133582631">.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free a,.mw-parser-output .citation .cs1-lock-free a{background:url("//upload.wikimedia.org/wikipedia/commons/6/65/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited a,.mw-parser-output .id-lock-registration a,.mw-parser-output .citation .cs1-lock-limited a,.mw-parser-output .citation .cs1-lock-registration a{background:url("//upload.wikimedia.org/wikipedia/commons/d/d6/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription a,.mw-parser-output .citation .cs1-lock-subscription a{background:url("//upload.wikimedia.org/wikipedia/commons/a/aa/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("//upload.wikimedia.org/wikipedia/commons/4/4c/Wikisource-logo.svg")right 0.1em center/12px no-repeat}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:#d33}.mw-parser-output .cs1-visible-error{color:#d33}.mw-parser-output .cs1-maint{display:none;color:#3a3;margin-left:0.3em}.mw-parser-output .cs1-format{font-size:95%}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}</style><cite id="CITEREFHowesThomas2008" class="citation book cs1">Howes, Lee; Thomas, David (2008). <i>GPU Gems 3 - Efficient Random Number Generation and Application Using CUDA</i>. Pearson Education, Inc. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/978-0-321-51526-1" title="Special:BookSources/978-0-321-51526-1"><bdi>978-0-321-51526-1</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=GPU+Gems+3+-+Efficient+Random+Number+Generation+and+Application+Using+CUDA&amp;rft.pub=Pearson+Education%2C+Inc.&amp;rft.date=2008&amp;rft.isbn=978-0-321-51526-1&amp;rft.aulast=Howes&amp;rft.aufirst=Lee&amp;rft.au=Thomas%2C+David&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABox%E2%80%93Muller+transform" class="Z3988"></span></li></ul>
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-1">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1133582631"><cite id="CITEREFBoxMuller1958" class="citation journal cs1">Box, G. E. P.; Muller, Mervin E. (1958). <a rel="nofollow" class="external text" href="https://doi.org/10.1214%2Faoms%2F1177706645">"A Note on the Generation of Random Normal Deviates"</a>. <i>The Annals of Mathematical Statistics</i>. <b>29</b> (2): 610611. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="cs1-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1214%2Faoms%2F1177706645">10.1214/aoms/1177706645</a></span>. <a href="/wiki/JSTOR_(identifier)" class="mw-redirect" title="JSTOR (identifier)">JSTOR</a>&#160;<a rel="nofollow" class="external text" href="https://www.jstor.org/stable/2237361">2237361</a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=The+Annals+of+Mathematical+Statistics&amp;rft.atitle=A+Note+on+the+Generation+of+Random+Normal+Deviates&amp;rft.volume=29&amp;rft.issue=2&amp;rft.pages=610-611&amp;rft.date=1958&amp;rft_id=info%3Adoi%2F10.1214%2Faoms%2F1177706645&amp;rft_id=https%3A%2F%2Fwww.jstor.org%2Fstable%2F2237361%23id-name%3DJSTOR&amp;rft.aulast=Box&amp;rft.aufirst=G.+E.+P.&amp;rft.au=Muller%2C+Mervin+E.&amp;rft_id=https%3A%2F%2Fdoi.org%2F10.1214%252Faoms%252F1177706645&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABox%E2%80%93Muller+transform" class="Z3988"></span></span>
</li>
<li id="cite_note-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-2">^</a></b></span> <span class="reference-text">Raymond E. A. C. Paley and Norbert Wiener <i>Fourier Transforms in the Complex Domain,</i> New York: American Mathematical Society (1934) §37.</span>
</li>
<li id="cite_note-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-3">^</a></b></span> <span class="reference-text">Kloeden and Platen, <i>Numerical Solutions of Stochastic Differential Equations</i>, pp. 1112</span>
</li>
<li id="cite_note-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-4">^</a></b></span> <span class="reference-text"><a href="#CITEREFHowesThomas2008">Howes &amp; Thomas 2008</a>.</span>
</li>
<li id="cite_note-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-5">^</a></b></span> <span class="reference-text">Sheldon Ross, <i>A First Course in Probability</i>, (2002), pp. 279281</span>
</li>
<li id="cite_note-Bell68-6"><span class="mw-cite-backlink">^ <a href="#cite_ref-Bell68_6-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-Bell68_6-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1133582631"><cite id="CITEREFBell1968" class="citation journal cs1">Bell, James R. (1968). <a rel="nofollow" class="external text" href="http://portal.acm.org/citation.cfm?doid=363397.363547">"Algorithm 334: Normal random deviates"</a>. <i>Communications of the ACM</i>. <b>11</b> (7): 498. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="cs1-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F363397.363547">10.1145/363397.363547</a></span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=Communications+of+the+ACM&amp;rft.atitle=Algorithm+334%3A+Normal+random+deviates&amp;rft.volume=11&amp;rft.issue=7&amp;rft.pages=498&amp;rft.date=1968&amp;rft_id=info%3Adoi%2F10.1145%2F363397.363547&amp;rft.aulast=Bell&amp;rft.aufirst=James+R.&amp;rft_id=http%3A%2F%2Fportal.acm.org%2Fcitation.cfm%3Fdoid%3D363397.363547&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABox%E2%80%93Muller+transform" class="Z3988"></span></span>
</li>
<li id="cite_note-7"><span class="mw-cite-backlink"><b><a href="#cite_ref-7">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1133582631"><cite id="CITEREFKnop1969" class="citation journal cs1">Knop, R. (1969). <a rel="nofollow" class="external text" href="http://portal.acm.org/citation.cfm?doid=362946.362996">"Remark on algorithm 334 &#91;G5&#93;: Normal random deviates"</a>. <i>Communications of the ACM</i>. <b>12</b> (5): 281. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="cs1-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F362946.362996">10.1145/362946.362996</a></span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=Communications+of+the+ACM&amp;rft.atitle=Remark+on+algorithm+334+%26%2391%3BG5%26%2393%3B%3A+Normal+random+deviates&amp;rft.volume=12&amp;rft.issue=5&amp;rft.pages=281&amp;rft.date=1969&amp;rft_id=info%3Adoi%2F10.1145%2F362946.362996&amp;rft.aulast=Knop&amp;rft.aufirst=R.&amp;rft_id=http%3A%2F%2Fportal.acm.org%2Fcitation.cfm%3Fdoid%3D362946.362996&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABox%E2%80%93Muller+transform" class="Z3988"></span></span>
</li>
<li id="cite_note-8"><span class="mw-cite-backlink"><b><a href="#cite_ref-8">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1133582631"><cite id="CITEREFKnuth1998" class="citation book cs1"><a href="/wiki/Donald_Knuth" title="Donald Knuth">Knuth, Donald</a> (1998). <i>The Art of Computer Programming: Volume 2: Seminumerical Algorithms</i>. p.&#160;122. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/0-201-89684-2" title="Special:BookSources/0-201-89684-2"><bdi>0-201-89684-2</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=The+Art+of+Computer+Programming%3A+Volume+2%3A+Seminumerical+Algorithms&amp;rft.pages=122&amp;rft.date=1998&amp;rft.isbn=0-201-89684-2&amp;rft.aulast=Knuth&amp;rft.aufirst=Donald&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABox%E2%80%93Muller+transform" class="Z3988"></span></span>
</li>
<li id="cite_note-Carter-9"><span class="mw-cite-backlink"><b><a href="#cite_ref-Carter_9-0">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="ftp://ftp.taygeta.com/pub/publications/randnum.tar.Z">Everett F. Carter, Jr., <i>The Generation and Application of Random Numbers</i>, Forth Dimensions (1994), Vol. 16, No. 1 &amp; 2.</a></span>
</li>
<li id="cite_note-10"><span class="mw-cite-backlink"><b><a href="#cite_ref-10">^</a></b></span> <span class="reference-text">The evaluation of 2<span class="texhtml mvar" style="font-style:italic;">π</span><i>U</i><sub>1</sub> is counted as one multiplication because the value of 2<span class="texhtml mvar" style="font-style:italic;">π</span> can be computed in advance and used repeatedly.</span>
</li>
</ol></div>
<h2><span class="mw-headline" id="External_links">External links</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Box%E2%80%93Muller_transform&amp;action=edit&amp;section=8" title="Edit section: External links"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></h2>
<ul><li><span class="citation mathworld" id="Reference-Mathworld-Box-Muller_Transformation"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1133582631"><cite id="CITEREFWeisstein" class="citation web cs1"><a href="/wiki/Eric_W._Weisstein" title="Eric W. Weisstein">Weisstein, Eric W.</a> <a rel="nofollow" class="external text" href="https://mathworld.wolfram.com/Box-MullerTransformation.html">"Box-Muller Transformation"</a>. <i><a href="/wiki/MathWorld" title="MathWorld">MathWorld</a></i>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=MathWorld&amp;rft.atitle=Box-Muller+Transformation&amp;rft.au=Weisstein%2C+Eric+W.&amp;rft_id=https%3A%2F%2Fmathworld.wolfram.com%2FBox-MullerTransformation.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ABox%E2%80%93Muller+transform" class="Z3988"></span></span></li>
<li><a rel="nofollow" class="external text" href="https://cockrum.net/code.html#TrueRNG_gaussian">How to Convert a Uniform Distribution to a Gaussian Distribution (C Code)</a></li></ul>
<!--
NewPP limit report
Parsed by mw1476
Cached time: 20231125182527
Cache expiry: 1814400
Reduced expiry: false
Complications: [varyrevisionsha1, showtoc]
CPU time usage: 0.237 seconds
Real time usage: 0.342 seconds
Preprocessor visited node count: 824/1000000
Postexpand include size: 13234/2097152 bytes
Template argument size: 764/2097152 bytes
Highest expansion depth: 8/100
Expensive parser function count: 2/500
Unstrip recursion depth: 1/20
Unstrip postexpand size: 25372/5000000 bytes
Lua time usage: 0.118/10.000 seconds
Lua memory usage: 4618326/52428800 bytes
Number of Wikibase entities loaded: 0/400
-->
<!--
Transclusion expansion time report (%,ms,calls,template)
100.00% 216.097 1 -total
32.23% 69.645 2 Template:Cite_book
24.98% 53.988 1 Template:Short_description
14.77% 31.908 2 Template:Pagetype
11.41% 24.654 1 Template:Harvnb
8.98% 19.401 1 Template:Main
7.98% 17.244 3 Template:Cite_journal
6.22% 13.445 1 Template:MathWorld
5.29% 11.426 2 Template:Main_other
4.53% 9.783 1 Template:SDcat
-->
<!-- Saved in parser cache with key enwiki:pcache:idhash:60758-0!canonical and timestamp 20231125182527 and revision id 1184897234. Rendering was triggered because: page-view
-->
</div><!--esi <esi:include src="/esitest-fa8a495983347898/content" /> --><noscript><img src="https://login.wikimedia.org/wiki/Special:CentralAutoLogin/start?type=1x1" alt="" width="1" height="1" style="border: none; position: absolute;"></noscript>
<div class="printfooter" data-nosnippet="">Retrieved from "<a dir="ltr" href="https://en.wikipedia.org/w/index.php?title=BoxMuller_transform&amp;oldid=1184897234">https://en.wikipedia.org/w/index.php?title=BoxMuller_transform&amp;oldid=1184897234</a>"</div></div>
<div id="catlinks" class="catlinks" data-mw="interface"><div id="mw-normal-catlinks" class="mw-normal-catlinks"><a href="/wiki/Help:Category" title="Help:Category">Categories</a>: <ul><li><a href="/wiki/Category:Transforms" title="Category:Transforms">Transforms</a></li><li><a href="/wiki/Category:Non-uniform_random_numbers" title="Category:Non-uniform random numbers">Non-uniform random numbers</a></li></ul></div><div id="mw-hidden-catlinks" class="mw-hidden-catlinks mw-hidden-cats-hidden">Hidden categories: <ul><li><a href="/wiki/Category:Articles_with_short_description" title="Category:Articles with short description">Articles with short description</a></li><li><a href="/wiki/Category:Short_description_matches_Wikidata" title="Category:Short description matches Wikidata">Short description matches Wikidata</a></li><li><a href="/wiki/Category:Articles_with_example_C%2B%2B_code" title="Category:Articles with example C++ code">Articles with example C++ code</a></li></ul></div></div>
</div>
</main>
</div>
<div class="mw-footer-container">
<footer id="footer" class="mw-footer" role="contentinfo" >
<ul id="footer-info">
<li id="footer-info-lastmod"> This page was last edited on 13 November 2023, at 08:41<span class="anonymous-show">&#160;(UTC)</span>.</li>
<li id="footer-info-copyright">Text is available under the <a rel="license" href="//en.wikipedia.org/wiki/Wikipedia:Text_of_the_Creative_Commons_Attribution-ShareAlike_4.0_International_License">Creative Commons Attribution-ShareAlike License 4.0</a><a rel="license" href="//en.wikipedia.org/wiki/Wikipedia:Text_of_the_Creative_Commons_Attribution-ShareAlike_4.0_International_License" style="display:none;"></a>;
additional terms may apply. By using this site, you agree to the <a href="//foundation.wikimedia.org/wiki/Terms_of_Use">Terms of Use</a> and <a href="//foundation.wikimedia.org/wiki/Privacy_policy">Privacy Policy</a>. Wikipedia® is a registered trademark of the <a href="//www.wikimediafoundation.org/">Wikimedia Foundation, Inc.</a>, a non-profit organization.</li>
</ul>
<ul id="footer-places">
<li id="footer-places-privacy"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy">Privacy policy</a></li>
<li id="footer-places-about"><a href="/wiki/Wikipedia:About">About Wikipedia</a></li>
<li id="footer-places-disclaimers"><a href="/wiki/Wikipedia:General_disclaimer">Disclaimers</a></li>
<li id="footer-places-contact"><a href="//en.wikipedia.org/wiki/Wikipedia:Contact_us">Contact Wikipedia</a></li>
<li id="footer-places-wm-codeofconduct"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Universal_Code_of_Conduct">Code of Conduct</a></li>
<li id="footer-places-developers"><a href="https://developer.wikimedia.org">Developers</a></li>
<li id="footer-places-statslink"><a href="https://stats.wikimedia.org/#/en.wikipedia.org">Statistics</a></li>
<li id="footer-places-cookiestatement"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Cookie_statement">Cookie statement</a></li>
<li id="footer-places-mobileview"><a href="//en.m.wikipedia.org/w/index.php?title=Box%E2%80%93Muller_transform&amp;mobileaction=toggle_view_mobile" class="noprint stopMobileRedirectToggle">Mobile view</a></li>
</ul>
<ul id="footer-icons" class="noprint">
<li id="footer-copyrightico"><a href="https://wikimediafoundation.org/"><img src="/static/images/footer/wikimedia-button.png" srcset="/static/images/footer/wikimedia-button-1.5x.png 1.5x, /static/images/footer/wikimedia-button-2x.png 2x" width="88" height="31" alt="Wikimedia Foundation" loading="lazy" /></a></li>
<li id="footer-poweredbyico"><a href="https://www.mediawiki.org/"><img src="/static/images/footer/poweredby_mediawiki_88x31.png" alt="Powered by MediaWiki" srcset="/static/images/footer/poweredby_mediawiki_132x47.png 1.5x, /static/images/footer/poweredby_mediawiki_176x62.png 2x" width="88" height="31" loading="lazy"></a></li>
</ul>
</footer>
</div>
</div>
</div>
<div class="vector-settings" id="p-dock-bottom">
<ul>
<li>
<button class="cdx-button cdx-button--icon-only vector-limited-width-toggle" id=""><span class="vector-icon mw-ui-icon-fullScreen mw-ui-icon-wikimedia-fullScreen"></span>
<span>Toggle limited content width</span>
</button>
</li>
</ul>
</div>
<script>(RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgHostname":"mw-web.eqiad.main-7bbb9c7bbf-t8k24","wgBackendResponseTime":128,"wgPageParseReport":{"limitreport":{"cputime":"0.237","walltime":"0.342","ppvisitednodes":{"value":824,"limit":1000000},"postexpandincludesize":{"value":13234,"limit":2097152},"templateargumentsize":{"value":764,"limit":2097152},"expansiondepth":{"value":8,"limit":100},"expensivefunctioncount":{"value":2,"limit":500},"unstrip-depth":{"value":1,"limit":20},"unstrip-size":{"value":25372,"limit":5000000},"entityaccesscount":{"value":0,"limit":400},"timingprofile":["100.00% 216.097 1 -total"," 32.23% 69.645 2 Template:Cite_book"," 24.98% 53.988 1 Template:Short_description"," 14.77% 31.908 2 Template:Pagetype"," 11.41% 24.654 1 Template:Harvnb"," 8.98% 19.401 1 Template:Main"," 7.98% 17.244 3 Template:Cite_journal"," 6.22% 13.445 1 Template:MathWorld"," 5.29% 11.426 2 Template:Main_other"," 4.53% 9.783 1 Template:SDcat"]},"scribunto":{"limitreport-timeusage":{"value":"0.118","limit":"10.000"},"limitreport-memusage":{"value":4618326,"limit":52428800},"limitreport-logs":"anchor_id_list = table#1 {\n [\"CITEREFBell1968\"] = 1,\n [\"CITEREFBoxMuller1958\"] = 1,\n [\"CITEREFHowesThomas2008\"] = 1,\n [\"CITEREFKnop1969\"] = 1,\n [\"CITEREFKnuth1998\"] = 1,\n}\ntemplate_list = table#1 {\n [\"=\"] = 4,\n [\"Cite book\"] = 2,\n [\"Cite journal\"] = 3,\n [\"DEFAULTSORT:Box-Muller Transform\"] = 1,\n [\"Harvnb\"] = 1,\n [\"Main\"] = 1,\n [\"MathWorld\"] = 1,\n [\"Nowrap\"] = 7,\n [\"Pi\"] = 5,\n [\"Short description\"] = 1,\n}\narticle_whitelist = table#1 {\n}\n"},"cachereport":{"origin":"mw1476","timestamp":"20231125182527","ttl":1814400,"transientcontent":false}}});});</script>
<script type="application/ld+json">{"@context":"https:\/\/schema.org","@type":"Article","name":"Box\u2013Muller transform","url":"https:\/\/en.wikipedia.org\/wiki\/Box%E2%80%93Muller_transform","sameAs":"http:\/\/www.wikidata.org\/entity\/Q895514","mainEntity":"http:\/\/www.wikidata.org\/entity\/Q895514","author":{"@type":"Organization","name":"Contributors to Wikimedia projects"},"publisher":{"@type":"Organization","name":"Wikimedia Foundation, Inc.","logo":{"@type":"ImageObject","url":"https:\/\/www.wikimedia.org\/static\/images\/wmf-hor-googpub.png"}},"datePublished":"2002-07-06T15:49:41Z","dateModified":"2023-11-13T08:41:28Z","image":"https:\/\/upload.wikimedia.org\/wikipedia\/commons\/1\/1f\/Box-Muller_transform_visualisation.svg","headline":"Statistical transform"}</script>
</body>
</html>