<?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" href="csound.css" type="text/css" /> <meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /> <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" title="randh"> <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" title="Description"> <a id="id3150329"></a> <h2>Description</h2> <p> Generates random numbers and holds them for a period of time. </p> </div> <div class="refsect1" title="Syntax"> <a id="id3150341"></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" title="Initialization"> <a id="id3150570"></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" title="Performance"> <a id="id3151254"></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" title="Examples"> <a id="id3151320"></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="id3151336"></a> <p class="title"> <b>Example 512. Example of the randh opcode.</b> </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> <pre class="programlisting"> <span class="csdtag"><CsoundSynthesizer></span> <span class="csdtag"><CsOptions></span> <span class="comment">; Select audio/midi flags here according to platform</span> <span class="comment">; Audio out Audio in</span> -odac -iadc <span class="comment">;;;RT audio I/O</span> <span class="comment">; For Non-realtime ouput leave only the line below:</span> <span class="comment">; -o randh.wav -W ;;; for file output any platform</span> <span class="csdtag"></CsOptions></span> <span class="csdtag"><CsInstruments></span> <span class="comment">; Initialize the global variables.</span> <span class="ohdr">sr</span> <span class="op">=</span> 44100 <span class="ohdr">kr</span> <span class="op">=</span> 4410 <span class="ohdr">ksmps</span> <span class="op">=</span> 10 <span class="ohdr">nchnls</span> <span class="op">=</span> 1 <span class="comment">; Instrument #1.</span> <span class="oblock">instr</span> 1 <span class="comment">; Choose a random frequency between 200 and 1000.</span> <span class="comment">; Generate new random numbers at 4 Hz.</span> <span class="comment">; kamp = 400</span> <span class="comment">; kcps = 4</span> <span class="comment">; iseed = 0.5</span> <span class="comment">; isize = 0</span> <span class="comment">; ioffset = 600</span> kcps <span class="opc">randh</span> 400, 4, 0.5, 0, 600 <span class="opc">printk2</span> kcps a1 <span class="opc">oscil</span> 30000, kcps, 1 <span class="opc">out</span> a1 <span class="oblock">endin</span> <span class="csdtag"></CsInstruments></span> <span class="csdtag"><CsScore></span> <span class="comment">; Table #1, a sine wave.</span> <span class="stamnt">f</span> 1 0 16384 10 1 <span class="comment">; Play Instrument #1 for one second.</span> <span class="stamnt">i</span> 1 0 5 <span class="stamnt">e</span> <span class="csdtag"></CsScore></span> <span class="csdtag"></CsoundSynthesizer></span> </pre> </div> </div> <p><br class="example-break" /> </p> </div> <div class="refsect1" title="See Also"> <a id="id3151374"></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 class="refsect1" title="Credits"> <a id="id3151400"></a> <h2>Credits</h2> <p>Example written by Kevin Conder.</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>