<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>nandeshwar.info &#187; random numbers</title>
	<atom:link href="http://nandeshwar.info/tag/random-numbers/feed/" rel="self" type="application/rss+xml" />
	<link>http://nandeshwar.info</link>
	<description></description>
	<lastBuildDate>Mon, 12 Dec 2011 21:33:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Random Numbers</title>
		<link>http://nandeshwar.info/2006/01/21/random-numbers/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=random-numbers</link>
		<comments>http://nandeshwar.info/2006/01/21/random-numbers/#comments</comments>
		<pubDate>Sat, 21 Jan 2006 17:59:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Useful Procedures]]></category>
		<category><![CDATA[excel functions]]></category>
		<category><![CDATA[random numbers]]></category>
		<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://a7n9.wordpress.com/2006/01/21/random-numbers/</guid>
		<description><![CDATA[Recently, I had the need of generating different types of random numbers. Although, Excel&#8217;s Data Analysis Toolpak can generate good random numbers, I had to create these functions to meet my needs. First: Unique Random Numbers This function was modified from ozgrid&#8217;s RandLotto function, which returns string. This function will return an array of unqiue [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I had the need of generating different types of random numbers. Although, Excel&#8217;s Data Analysis Toolpak can generate good random numbers, I had to create these functions to meet my needs.</p>
<p>First: Unique Random Numbers<br />
This function was modified from ozgrid&#8217;s RandLotto function, which returns string. This function will return an array of unqiue random integers in the given range. If you want to return more than one number then this function should be entered as an array formula with Ctrl + Shift + Enter.</p>
<div id="code"><span style="font-family: Courier;"><span style="color:#00007F;">Function</span> UniqueRand(lngSmallest <span style="color:#00007F;">As</span> <span style="color:#00007F;">Long</span>, lngHighest <span style="color:#00007F;">As</span> <span style="color:#00007F;">Long</span>, HowManyNos <span style="color:#00007F;">As</span> <span style="color:#00007F;">Long</span>) <span style="color:#00007F;">As</span> <span style="color:#00007F;">Long</span>()<br />
<span style="color:#007F00;">&#8216;modified from http://www.ozgrid.com/VBA/RandomNumbers.htm</span><br />
<span style="color:#00007F;">Dim</span> iArr <span style="color:#00007F;">As</span> <span style="color:#00007F;">Variant</span><br />
<span style="color:#00007F;">Dim</span> i <span style="color:#00007F;">As</span> <span style="color:#00007F;">Integer</span><br />
<span style="color:#00007F;">Dim</span> r <span style="color:#00007F;">As</span> <span style="color:#00007F;">Integer</span><br />
<span style="color:#00007F;">Dim</span> temp <span style="color:#00007F;">As</span> <span style="color:#00007F;">Integer</span><br />
Application.Volatile<br />
<span style="color:#00007F;">ReDim</span> iArr(lngSmallest <span style="color:#00007F;">To</span> lngHighest)<br />
<span style="color:#00007F;">For</span> i = lngSmallest <span style="color:#00007F;">To</span> lngHighest<br />
iArr(i) = i<br />
<span style="color:#00007F;">Next</span> i<br />
<span style="color:#00007F;">For</span> i = lngHighest <span style="color:#00007F;">To</span> lngSmallest + 1 <span style="color:#00007F;">Step</span> -1<br />
r = Int(Rnd() * (i &#8211; lngSmallest + 1)) + lngSmallest<br />
temp = iArr(r)<br />
iArr(r) = iArr(i)<br />
iArr(i) = temp<br />
<span style="color:#00007F;">Next</span> i<br />
<span style="color:#00007F;">Dim</span> resultArr() <span style="color:#00007F;">As</span> Long: <span style="color:#00007F;">ReDim</span> resultArr(HowManyNos &#8211; 1, 0)<br />
<span style="color:#00007F;">For</span> i = lngSmallest <span style="color:#00007F;">To</span> lngSmallest + HowManyNos &#8211; 1<br />
resultArr(j, 0) = iArr(i)<br />
j = j + 1<br />
<span style="color:#00007F;">Next</span> i<br />
UniqueRand = resultArr<br />
<span style="color:#00007F;">End</span> <span style="color:#00007F;">Function</span></span></div>
<p>Second: Gaussian or Normal Random Numbers with specified mean and Standard deviation(SD). Now, this function is different than the Analysis toolpak utility because it generates random numbers on a fixed mean and Standard deviation. This function will allow the user to generate random numbers each with different mean and SD.</p>
<div id="code"><span style="font-family: Courier;"><span style="color:#007F00;">&#8216;This function will generate Gaussian or Normal Random Numbers based on given mean and SD</span><br />
<span style="color:#00007F;">Public</span> <span style="color:#00007F;">Function</span> GenGaussNoise(mean <span style="color:#00007F;">As</span> <span style="color:#00007F;">Double</span>, SD <span style="color:#00007F;">As</span> <span style="color:#00007F;">Double</span>, HowMany <span style="color:#00007F;">As</span> <span style="color:#00007F;">Long</span>) <span style="color:#00007F;">As</span> <span style="color:#00007F;">Double</span>()<br />
<span style="color:#00007F;">Dim</span> x <span style="color:#00007F;">As</span> <span style="color:#00007F;">Double</span>, i <span style="color:#00007F;">As</span> <span style="color:#00007F;">Long</span>, j <span style="color:#00007F;">As</span> <span style="color:#00007F;">Long</span><br />
itr = 50<br />
<span style="color:#00007F;">Dim</span> dblResArr() <span style="color:#00007F;">As</span> Double: <span style="color:#00007F;">ReDim</span> dblResArr(HowMany &#8211; 1, 0)<br />
<span style="color:#00007F;">For</span> j = 1 <span style="color:#00007F;">To</span> HowMany<br />
x = 0<br />
<span style="color:#00007F;">For</span> i = 1 <span style="color:#00007F;">To</span> itr<br />
Randomize<br />
U = Rnd<br />
x = x + U<br />
<span style="color:#00007F;">Next</span> i<br />
<span style="color:#007F00;">&#8216; /* for uniform randoms in [0,1], mu = 0.5 and var = 1/12 */</span><br />
<span style="color:#007F00;">&#8216; /* adjust X so mu = 0 and var = 1 */</span><br />
x = x &#8211; itr / 2             <span style="color:#007F00;">&#8216; /* set mean to 0 */</span><br />
x = x * Sqr(12 / itr)     <span style="color:#007F00;">&#8216;  /* adjust variance to 1 */</span><br />
dblResArr(j &#8211; 1, 0) = mean + SD * x<br />
<span style="color:#00007F;">Next</span> j<br />
GenGaussNoise = dblResArr<br />
<span style="color:#00007F;">End</span> <span style="color:#00007F;">Function</span></span></div>
<p>Third: Generate white noise or Guassian or Normal random numbers with mean = 0 and SD =1. Although, this could be achieved by the previous function, this function uses Box-Muller method. In this function too, you can use different mean and SD, although if not provided it would take mean =0 and SD=1</p>
<div id="code"><span style="font-family: Courier;"><span style="color:#00007F;">Public</span> <span style="color:#00007F;">Function</span> GenWhiteNoise(HowMany <span style="color:#00007F;">As</span> <span style="color:#00007F;">Long</span>, <span style="color:#00007F;">Optional</span> mean <span style="color:#00007F;">As</span> <span style="color:#00007F;">Double</span> = 0, <span style="color:#00007F;">Optional</span> variance <span style="color:#00007F;">As</span> <span style="color:#00007F;">Double</span> = 1) <span style="color:#00007F;">As</span> <span style="color:#00007F;">Double</span>()<br />
<span style="color:#007F00;">&#8216;Returns a normally distributed random variate with mean 0 and variance 1, a.k.a. &#8220;White Noise&#8221;.</span><br />
<span style="color:#007F00;">&#8216;  Uses the Box-Muller method</span><br />
<span style="color:#00007F;">Dim</span> Value1 <span style="color:#00007F;">As</span> <span style="color:#00007F;">Single</span>, Value2 <span style="color:#00007F;">As</span> <span style="color:#00007F;">Single</span>, Fac <span style="color:#00007F;">As</span> <span style="color:#00007F;">Single</span>, Rsq <span style="color:#00007F;">As</span> <span style="color:#00007F;">Single</span>, SD <span style="color:#00007F;">As</span> <span style="color:#00007F;">Double</span><br />
<span style="color:#00007F;">Dim</span> dblResArr() <span style="color:#00007F;">As</span> Double: <span style="color:#00007F;">ReDim</span> dblResArr(HowMany &#8211; 1, 0)<br />
SD = Sqr(variance)<br />
<span style="color:#00007F;">For<br />
pan&gt; i = 1 <span style="color:#00007F;">To</span> HowMany<br />
<span style="color:#00007F;">Do</span><br />
Randomize<br />
Value1 = 2 * Rnd &#8211; 1<br />
Value2 = 2 * Rnd &#8211; 1<br />
Rsq = Value1 ^ 2 + Value2 ^ 2<br />
<span style="color:#00007F;">Loop</span> <span style="color:#00007F;">Until</span> Rsq &gt; 0 And Rsq &lt; 1<br />
Fac = (-2 * Log(Rsq) / Rsq) ^ 0.5<br />
<span style="color:#00007F;">If</span> Rnd &lt; 0.5 <span style="color:#00007F;">Then</span><br />
dblResArr(i &#8211; 1, 0) = mean + SD * Value1 * Fac<br />
<span style="color:#00007F;">Else</span><br />
dblResArr(i &#8211; 1, 0) = mean + SD * Value2 * Fac<br />
<span style="color:#00007F;">End</span> <span style="color:#00007F;">If</span><br />
<span style="color:#00007F;">Next</span> i<br />
GenWhiteNoise = dblResArr<br />
<span style="color:#00007F;">End</span> <span style="color:#00007F;">Function</span></span></span></div>
<p>This is a screenshot of the Excel file. Also, the original Excel file can be downloaded <a href="http://www.nandeshwar.info/projects/xlblog/files/AllTypeofRandomNos.xls">here</a>.<br />
<a href="http://www.nandeshwar.info/projects/xlblog/uploaded_images/RandomNumbers-715877.JPG"><img style="display:block;text-align:center;cursor:hand;margin:0 auto 10px;" src="http://www.nandeshwar.info/projects/xlblog/uploaded_images/RandomNumbers-708779.JPG" border="0" alt="" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://nandeshwar.info/2006/01/21/random-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Excel Instructions &#8211; Exponential Distribution</title>
		<link>http://nandeshwar.info/2005/09/12/excel-instructions-exponential-distribution/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=excel-instructions-exponential-distribution</link>
		<comments>http://nandeshwar.info/2005/09/12/excel-instructions-exponential-distribution/#comments</comments>
		<pubDate>Mon, 12 Sep 2005 22:25:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Note Don]]></category>
		<category><![CDATA[random numbers]]></category>

		<guid isPermaLink="false">http://a7n9.wordpress.com/2005/09/12/excel-instructions-exponential-distribution/</guid>
		<description><![CDATA[Excel Instructions &#8211; Exponential Distribution: &#8220;Exponential Excel cannot directly generate data from an exponential; however, the following procedure can be used to obtain random observations from an exponential distribution. The first step is to create a set of uniform random numbers between 0 and 1, see Uniform for more information. To obtain the exponential random [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.statsclass.com/excel/misc/exp_dist.html">Excel Instructions &#8211; Exponential Distribution</a>: &#8220;Exponential<br />
<br />Excel cannot directly generate data from an exponential; however, the following procedure can be used to obtain random observations from an exponential distribution.</p>
<p>The first step is to create a set of uniform random numbers between 0 and 1, see Uniform for more information.<br />
<br />To obtain the exponential random numbers, we need to use the following formula:</p>
<p>exponential random number = &#8211; mean*log(1 &#8211; unif, 2.71828)</p>
<p>where<br />
<br />mean is the mean for the exponential distribution<br />
<br />unif is a uniform random number</p>
<p>Note: Don&#8217;t forget the &#8211; in front of the mean.</p>
<p>Copy the formula down for all observations. See &#8216;How do I edit my work?&#8217; for more information on copy and pasting. &#8220;</p>
]]></content:encoded>
			<wfw:commentRss>http://nandeshwar.info/2005/09/12/excel-instructions-exponential-distribution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

