<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/253925</link>
    <title>MATLAB Central Newsreader - random numbers</title>
    <description>Feed for thread: random numbers</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Wed, 17 Jun 2009 09:03:01 -0400</pubDate>
      <title>random numbers</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/253925#658041</link>
      <author>remi </author>
      <description>Hello.... please i need your help with this. I want to generate a random sequence of that value...so i used this [Msgsize= round(rand(floor(number),1))]. After generating that i used a key such that whenever i  call the function it gives me exactly that particular random sequence. i know i'm generating randomly but using the key should give me the exact numbers back, because i need the numbers to not change.&lt;br&gt;
&lt;br&gt;
Please can someone let me know if i'm on the right track..&lt;br&gt;
many thanks&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
function [Msgsize] = sizetext(number,key)&lt;br&gt;
number = 300 * 15;&lt;br&gt;
Msgsize= round(rand(floor(number),1));&lt;br&gt;
Msgsize= randintrlv(Msgsize, key);</description>
    </item>
    <item>
      <pubDate>Wed, 17 Jun 2009 11:01:02 -0400</pubDate>
      <title>Re: random numbers</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/253925#658066</link>
      <author>Ulf Graewe</author>
      <description>you can something like this&lt;br&gt;
&lt;br&gt;
function [Msgsize] = sizetext(number,key)&lt;br&gt;
&lt;br&gt;
if ~isemptey(key)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rand('state',key)&lt;br&gt;
endif&lt;br&gt;
number = 300 * 15;&lt;br&gt;
Msgsize= round(rand(floor(number),1));&lt;br&gt;
Msgsize= randintrlv(Msgsize);&lt;br&gt;
&lt;br&gt;
by using the rand('state',number) command, you can set the generator to a certain state and thus get the same sequence of random numbers.&lt;br&gt;
&lt;br&gt;
simply try in the command line&lt;br&gt;
&lt;br&gt;
rand('state',1000),rand,rand&lt;br&gt;
&lt;br&gt;
rand('state',1000),rand,rand('state',1000), rand&lt;br&gt;
&lt;br&gt;
and see the difference!&lt;br&gt;
&lt;br&gt;
doc rand gives more information</description>
    </item>
    <item>
      <pubDate>Wed, 17 Jun 2009 13:34:38 -0400</pubDate>
      <title>Re: random numbers</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/253925#658118</link>
      <author>Steven Lord</author>
      <description>&lt;br&gt;
&quot;Ulf Graewe&quot; &amp;lt;graewe@icbm.de.skip.this&amp;gt; wrote in message &lt;br&gt;
news:h1aide$bek$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; you can something like this&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; function [Msgsize] = sizetext(number,key)&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; if ~isemptey(key)&lt;br&gt;
&amp;gt;    rand('state',key)&lt;br&gt;
&amp;gt; endif&lt;br&gt;
&amp;gt; number = 300 * 15;&lt;br&gt;
&amp;gt; Msgsize= round(rand(floor(number),1));&lt;br&gt;
&amp;gt; Msgsize= randintrlv(Msgsize);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; by using the rand('state',number) command, you can set the generator to a &lt;br&gt;
&amp;gt; certain state and thus get the same sequence of random numbers.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; simply try in the command line&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; rand('state',1000),rand,rand&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; rand('state',1000),rand,rand('state',1000), rand&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; and see the difference!&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; doc rand gives more information&lt;br&gt;
&lt;br&gt;
Since the introduction of the RandStream random number generator &lt;br&gt;
infrastructure, we recommend using RandStream methods and properties to &lt;br&gt;
control the random number generators, rather than the rand(keyword, ...) &lt;br&gt;
syntax.  Doing so allows you to isolate your own random number generator &lt;br&gt;
streams, so that your random number generation will not affect others that &lt;br&gt;
are using RandStream generators and their random number generation will not &lt;br&gt;
affect yours.  In addition, if you have RandStream available, you will also &lt;br&gt;
have the RANDI function/method available, which can directly generate &lt;br&gt;
integer values.  This means you won't need to do ROUND/CEIL/FLOOR/FIX of a &lt;br&gt;
scaled call to RAND.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
function msgsize = sizetext(number, key)&lt;br&gt;
mygenerator = RandStream.create('mt19937ar', 'Seed', key);&lt;br&gt;
numElements = 300*15;&lt;br&gt;
% Generate a numElements-by-1 matrix of integers between 0 and 1 inclusive&lt;br&gt;
% using the generator object I created above.&lt;br&gt;
% mt19937ar is the Mersenne Twister algorithm.  For a list of other &lt;br&gt;
algorithms&lt;br&gt;
% that are available, see:&lt;br&gt;
% &lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/techdoc/ref/randstream.list.html&quot;&gt;http://www.mathworks.com/access/helpdesk/help/techdoc/ref/randstream.list.html&lt;/a&gt;&lt;br&gt;
msgsize = randi(mygenerator, [0 1], numElements, 1)&lt;br&gt;
msgsize = randintrlv(msgsize);&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Steve Lord&lt;br&gt;
slord@mathworks.com </description>
    </item>
  </channel>
</rss>

