<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Two different ways to generate random numbers -the same or different ?! in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Two-different-ways-to-generate-random-numbers-the-same-or/m-p/876930#M346425</link>
    <description>Hi! I will have a further look into this. /Br AndersS</description>
    <pubDate>Mon, 22 May 2023 17:15:28 GMT</pubDate>
    <dc:creator>AndersS</dc:creator>
    <dc:date>2023-05-22T17:15:28Z</dc:date>
    <item>
      <title>Two different ways to generate random numbers -the same or different ?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-different-ways-to-generate-random-numbers-the-same-or/m-p/876823#M346388</link>
      <description>&lt;P&gt;Hi!&amp;nbsp; I am doing some computer experiments with Gumbel random numbers.&lt;BR /&gt;1) According to the books and manuals:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CALL STREAMINIT(2);&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X= RAND("GUMBEL", MY, SCALE);&lt;BR /&gt;An alternative:&amp;nbsp;&amp;nbsp;&amp;nbsp;Xi= MY - SCALE*LOG( -LOG(RAND('UNIFORM')));&lt;/P&gt;
&lt;P&gt;These two seem to produce results that are identical.&lt;BR /&gt;I have used both to produce a lot of random numbers. Works fine.&amp;nbsp;Then I calculated the Mean, StdDev and a lot of quantiles.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) An alternative, when producing many random numbers is the following:&amp;nbsp;&amp;nbsp; &amp;nbsp;X= MY - SCALE*LOG(-LOG(Step));&lt;BR /&gt;where Step is the index in a do-loop. 5Mi values.&amp;nbsp;Then I calculated the Mean, StdDev and a lot of quantiles. &lt;BR /&gt;The values are&amp;nbsp;almost the same as above, with very small differences,&lt;BR /&gt;&lt;BR /&gt;Fine - OR?&lt;/P&gt;
&lt;P&gt;When I look at the values generated using 2) in some small intervals e.g. around the median&amp;nbsp;the values look very smooth and nice. &lt;BR /&gt;When I do the same using the values produced by 1) the&amp;nbsp;values are not at all that smooth, but vary up and down.&lt;BR /&gt;&lt;BR /&gt;Question: Is this described in any paper? Are the values produced in 2) also random numbers.&lt;/P&gt;
&lt;P&gt;I would appreciate som comments and advice on this matter.&lt;/P&gt;
&lt;P&gt;Best Regards AndersS&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 May 2023 20:33:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-different-ways-to-generate-random-numbers-the-same-or/m-p/876823#M346388</guid>
      <dc:creator>AndersS</dc:creator>
      <dc:date>2023-05-21T20:33:36Z</dc:date>
    </item>
    <item>
      <title>Re: Two different ways to generate random numbers -the same or different ?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-different-ways-to-generate-random-numbers-the-same-or/m-p/876825#M346390</link>
      <description>&lt;P&gt;I would expect close values to some extent when driven by a "do loop". The index takes very specific increments, which will limit the resulting output to small changes. That is built into the formula you use.&lt;/P&gt;
&lt;P&gt;Look at the behavior of -log(step) by itself. You can see that as your "step" increases the value change of the function result gets smaller:&lt;/P&gt;
&lt;PRE&gt;data junk; 
   do i=1 to 100;
      y= -log(i);
      output;
   end;
run;

proc sgplot;
   scatter x=i y=y;
run;&lt;/PRE&gt;
&lt;P&gt;I would not, personally, call method 2 "random" in any way. It is determined by the value of 3 variables. Plug in the same 3 values you get the same result, hence not random. It may generate a range of values similar to a specific random number distribution but for any of the traditional uses of random values I wouldn't touch that approach, at least not without considerable addition to the code.&lt;/P&gt;</description>
      <pubDate>Sun, 21 May 2023 20:51:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-different-ways-to-generate-random-numbers-the-same-or/m-p/876825#M346390</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-21T20:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: Two different ways to generate random numbers -the same or different ?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-different-ways-to-generate-random-numbers-the-same-or/m-p/876838#M346392</link>
      <description>&lt;P&gt;to get random numbers with method 2 you would need something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let n=5000000;

array _x{&amp;amp;n.} _temporary_;

if _n_ = 1 then do step = 1 to &amp;amp;n.;
	_X{step} = MY - SCALE*LOG(-LOG(Step));
	end;

do step = 1 to &amp;amp;n.;
	X = _X{rand("integer", &amp;amp;n.)};
	output;
	end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;those would look almost OK, as long as n is large, but wouldn't save any significant CPU resources.&lt;/P&gt;</description>
      <pubDate>Mon, 22 May 2023 04:37:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-different-ways-to-generate-random-numbers-the-same-or/m-p/876838#M346392</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2023-05-22T04:37:51Z</dc:date>
    </item>
    <item>
      <title>Re: Two different ways to generate random numbers -the same or different ?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-different-ways-to-generate-random-numbers-the-same-or/m-p/876927#M346423</link>
      <description>Hi! Many thanks. I agrere with you. /Br AndersS</description>
      <pubDate>Mon, 22 May 2023 16:37:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-different-ways-to-generate-random-numbers-the-same-or/m-p/876927#M346423</guid>
      <dc:creator>AndersS</dc:creator>
      <dc:date>2023-05-22T16:37:45Z</dc:date>
    </item>
    <item>
      <title>Re: Two different ways to generate random numbers -the same or different ?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Two-different-ways-to-generate-random-numbers-the-same-or/m-p/876930#M346425</link>
      <description>Hi! I will have a further look into this. /Br AndersS</description>
      <pubDate>Mon, 22 May 2023 17:15:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Two-different-ways-to-generate-random-numbers-the-same-or/m-p/876930#M346425</guid>
      <dc:creator>AndersS</dc:creator>
      <dc:date>2023-05-22T17:15:28Z</dc:date>
    </item>
  </channel>
</rss>

