<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>randh</title> <link rel="stylesheet" type="text/css" href="csound.css" /> <link rel="stylesheet" type="text/css" href="syntax-highlighting.css" /> <meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /> <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" /> <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" /> <link rel="prev" href="rand.html" title="rand" /> <link rel="next" href="randi.html" title="randi" /> </head> <body> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center">randh</th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="rand.html">Prev</a> </td> <th width="60%" align="center">Orchestra Opcodes and Operators</th> <td width="20%" align="right"> <a accesskey="n" href="randi.html">Next</a></td> </tr> </table> <hr /> </div> <div class="refentry"> <a id="randh"></a> <div class="titlepage"></div> <a id="IndexRandh" class="indexterm"></a> <div class="refnamediv"> <h2> <span class="refentrytitle">randh</span> </h2> <p>randh — Generates random numbers and holds them for a period of time. </p> </div> <div class="refsect1"> <a id="idm281472896865704"></a> <h2>Description</h2> <p> Generates random numbers and holds them for a period of time. </p> </div> <div class="refsect1"> <a id="idm281472896795832"></a> <h2>Syntax</h2> <pre class="synopsis">ares <span class="command"><strong>randh</strong></span> xamp, xcps [, iseed] [, isize] [, ioffset]</pre> <pre class="synopsis">kres <span class="command"><strong>randh</strong></span> kamp, kcps [, iseed] [, isize] [, ioffset]</pre> </div> <div class="refsect1"> <a id="idm281472896792088"></a> <h2>Initialization</h2> <p> <span class="emphasis"><em>iseed</em></span> (optional, default=0.5) -- seed value for the recursive pseudo-random formula. A value between 0 and +1 will produce an initial output of <span class="emphasis"><em>kamp * iseed.</em></span> A negative value will cause seed re-initialization to be skipped. A value greater than 1 will seed from system time, this is the best option to generate a different random sequence for each run. </p> <p> <span class="emphasis"><em>isize</em></span> (optional, default=0) -- if zero, a 16 bit number is generated. If non-zero, a 31-bit random number is generated. Default is 0. </p> <p> <span class="emphasis"><em>ioffset</em></span> (optional, default=0) -- a base value added to the random result. New in Csound version 4.03. </p> </div> <div class="refsect1"> <a id="idm281472896787304"></a> <h2>Performance</h2> <p> <span class="emphasis"><em>kamp, xamp</em></span> -- range over which random numbers are distributed. </p> <p> <span class="emphasis"><em>kcps, xcps</em></span> -- the frequency which new random numbers are generated. </p> <p> The internal pseudo-random formula produces values which are uniformly distributed over the range -<span class="emphasis"><em>kamp</em></span> to +<span class="emphasis"><em>kamp</em></span>. <span class="emphasis"><em>rand</em></span> will thus generate uniform white noise with an R.M.S value of <span class="emphasis"><em>kamp / root 2</em></span>. </p> <p> The remaining units produce band-limited noise: the <span class="emphasis"><em>kcps</em></span> and <span class="emphasis"><em>xcps</em></span> parameters permit the user to specify that new random numbers are to be generated at a rate less than the sampling or control frequencies. <span class="emphasis"><em>randh</em></span> will hold each new number for the period of the specified cycle. </p> </div> <div class="refsect1"> <a id="idm281472896780200"></a> <h2>Examples</h2> <p> Here is an example of the randh opcode. It uses the file <a class="ulink" href="examples/randh.csd" target="_top"><em class="citetitle">randh.csd</em></a>. </p> <div class="example"> <a id="idm281472896778344"></a> <p class="title"> <strong>Example 803. Example of the randh opcode.</strong> </p> <div class="example-contents"> <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p> <div class="refsect1"> <a id="idm281472718237672"></a> <pre class="programlisting"> <span class="nt"><CsoundSynthesizer></span> <span class="nt"><CsOptions></span> <span class="c1">; Select audio/midi flags here according to platform</span> -odac <span class="c1">;;;realtime audio out</span> <span class="c1">;-iadc ;;;uncomment -iadc if RT audio input is needed too</span> <span class="c1">; For Non-realtime ouput leave only the line below:</span> <span class="c1">; -o randh.wav -W ;;; for file output any platform</span> <span class="nt"></CsOptions></span> <span class="nt"><CsInstruments></span> <span class="vg">sr</span> <span class="o">=</span> <span class="mi">44100</span> <span class="vg">ksmps</span> <span class="o">=</span> <span class="mi">32</span> <span class="vg">nchnls</span> <span class="o">=</span> <span class="mi">2</span> <span class="vg">0dbfs</span> <span class="o">=</span> <span class="mi">1</span> <span class="kd">instr</span> <span class="nf">1</span> <span class="c1">;same values every time</span> k<span class="n">rnd</span> <span class="nb">randh</span> <span class="mi">100</span><span class="p">,</span> <span class="mi">10</span> <span class="nb">printk2</span> k<span class="n">rnd</span> <span class="c1">; look </span> a<span class="n">out</span> <span class="nb">oscili</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mi">440</span><span class="o">+</span>k<span class="n">rnd</span><span class="p">,</span> <span class="mi">1</span> <span class="c1">; & listen</span> <span class="nb">outs</span> a<span class="n">out</span><span class="p">,</span> a<span class="n">out</span> <span class="kd">endin</span> <span class="kd">instr</span> <span class="nf">2</span> <span class="c1">;different values every time</span> k<span class="n">rnd</span> <span class="nb">randh</span> <span class="mi">100</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">10</span> <span class="c1">; seed from system clock</span> <span class="nb">printk2</span> k<span class="n">rnd</span> <span class="c1">; look </span> a<span class="n">out</span> <span class="nb">oscili</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mi">440</span><span class="o">+</span>k<span class="n">rnd</span><span class="p">,</span> <span class="mi">1</span> <span class="c1">; & listen</span> <span class="nb">outs</span> a<span class="n">out</span><span class="p">,</span> a<span class="n">out</span> <span class="kd">endin</span> <span class="nt"></CsInstruments></span> <span class="nt"><CsScore></span> <span class="nb">f</span> <span class="mi">1</span> <span class="mi">0</span> <span class="mi">16384</span> <span class="mi">10</span> <span class="mi">1</span> <span class="c1">;sine wave.</span> <span class="nb">i</span> <span class="mi">1</span> <span class="mi">0</span> <span class="mi">1</span> <span class="nb">i</span> <span class="mi">2</span> <span class="mi">2</span> <span class="mi">1</span> <span class="nb">e</span> <span class="nt"></CsScore></span> <span class="nt"></CsoundSynthesizer></span> </pre> </div> </div> </div> <p><br class="example-break" /> </p> <p> The example will produce the following output: </p> <pre class="screen"> i1 50.00000 i1 50.00305 i1 97.68677 i1 -44.25354 i1 -61.56006 i1 -75.91248 i1 67.57202 i1 12.83875 i1 5.39551 i1 -95.18738 WARNING: Seeding from current time 684387922 i2 -13.81226 i2 -16.49475 i2 69.51904 i2 35.04944 i2 47.47925 i2 63.25378 i2 -59.61914 i2 50.93079 i2 -6.46362 i2 5.89294 </pre> <p> </p> </div> <div class="refsect1"> <a id="idm281472896772232"></a> <h2>See Also</h2> <p> <a class="link" href="rand.html" title="rand"><em class="citetitle">rand</em></a>, <a class="link" href="randi.html" title="randi"><em class="citetitle">randi</em></a> </p> </div> </div> <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"><a accesskey="p" href="rand.html">Prev</a> </td> <td width="20%" align="center"> <a accesskey="u" href="OpcodesTop.html">Up</a> </td> <td width="40%" align="right"> <a accesskey="n" href="randi.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">rand </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top"> randi</td> </tr> </table> </div> </body> </html>