<?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>rnd</title> <link rel="stylesheet" type="text/css" href="csound.css" /> <meta name="generator" content="DocBook XSL Stylesheets V1.76.1" /> <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="rms.html" title="rms" /> <link rel="next" href="rnd31.html" title="rnd31" /> </head> <body> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center">rnd</th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="rms.html">Prev</a> </td> <th width="60%" align="center">Orchestra Opcodes and Operators</th> <td width="20%" align="right"> <a accesskey="n" href="rnd31.html">Next</a></td> </tr> </table> <hr /> </div> <div class="refentry" title="rnd"> <a id="rnd"></a> <div class="titlepage"></div> <a id="IndexRnd" class="indexterm"></a> <div class="refnamediv"> <h2> <span class="refentrytitle">rnd</span> </h2> <p>rnd — Returns a random number in a unipolar range at the rate given by the input argument. </p> </div> <div class="refsect1" title="Description"> <a id="idp40951632"></a> <h2>Description</h2> <p> Returns a random number in a unipolar range at the rate given by the input argument. </p> </div> <div class="refsect1" title="Syntax"> <a id="idp40952440"></a> <h2>Syntax</h2> <pre class="synopsis"><span class="command"><strong>rnd</strong></span>(x) (init- or control-rate only)</pre> <p> Where the argument within the parentheses may be an expression. These value converters sample a global random sequence, but do not reference <span class="emphasis"><em>seed</em></span>. The result can be a term in a further expression. </p> </div> <div class="refsect1" title="Performance"> <a id="idp40963504"></a> <h2>Performance</h2> <p> Returns a random number in the unipolar range 0 to <span class="emphasis"><em>x</em></span>. </p> </div> <div class="refsect1" title="Examples"> <a id="idp40964392"></a> <h2>Examples</h2> <p> Here is an example of the rnd opcode. It uses the file <a class="ulink" href="examples/rnd.csd" target="_top"><em class="citetitle">rnd.csd</em></a>. </p> <div class="example"> <a id="idp40965368"></a> <p class="title"> <strong>Example 727. Example of the rnd 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> <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 rnd.wav -W ;;; for file output any platform</span> <span class="csdtag"></CsOptions></span> <span class="csdtag"><CsInstruments></span> <span class="comment">; Andres Cabrera 2010</span> <span class="ohdr">sr</span> <span class="op">=</span> 44100 <span class="ohdr">ksmps</span> <span class="op">=</span> 4410 <span class="ohdr">nchnls</span> <span class="op">=</span> 1 <span class="ohdr">0dbfs</span> <span class="op">=</span> 1 <span class="oblock">instr</span> 1 <span class="comment">; Generate a random number from 0 to 10.</span> irand <span class="op">=</span> <span class="opc">rnd</span>(10) <span class="opc">print</span> irand <span class="oblock">endin</span> <span class="oblock">instr</span> 2 klimit <span class="opc">init</span> 10 krand <span class="op">=</span> <span class="opc">rnd</span>(klimit) <span class="opc">printk</span> 0, krand <span class="oblock">endin</span> <span class="csdtag"></CsInstruments></span> <span class="csdtag"><CsScore></span> <span class="stamnt">i</span> 1 0 1 <span class="comment">; Generate 1 number</span> <span class="stamnt">i</span> 1 0 1 <span class="comment">; Generate another number</span> <span class="stamnt">i</span> 1 0 1 <span class="comment">; yet another number</span> <span class="stamnt">i</span> 2 2 1 <span class="comment">; 1 second prints 9 values (kr = 10)</span> <span class="stamnt">e</span> <span class="csdtag"></CsScore></span> <span class="csdtag"></CsoundSynthesizer></span> </pre> </div> </div> <p><br class="example-break" /> Its output should be: </p> <pre class="screen">SECTION 1: new alloc for instr 1: instr 1: irand = 9.735 new alloc for instr 1: instr 1: irand = 1.394 new alloc for instr 1: instr 1: irand = 7.695 midi channel 1 now using instr 1 B 0.000 .. 2.000 T 2.000 TT 2.000 M: 0.00000 new alloc for instr 2: i 2 time 2.10000: 5.25005 i 2 time 2.20000: 6.22665 i 2 time 2.30000: 9.69511 i 2 time 2.40000: 7.16822 i 2 time 2.50000: 9.45134 i 2 time 2.60000: 1.34123 i 2 time 2.70000: 2.09879 i 2 time 2.80000: 2.36001 i 2 time 2.90000: 0.03553</pre> <p> </p> </div> <div class="refsect1" title="See Also"> <a id="idp41029688"></a> <h2>See Also</h2> <p> <a class="link" href="birnd.html" title="birnd"><em class="citetitle">birnd</em></a> </p> </div> <div class="refsect1" title="Credits"> <a id="idp41030760"></a> <h2>Credits</h2> <p> </p> <table border="0" summary="Simple list" class="simplelist"> <tr> <td>Author: Barry L. Vercoe</td> </tr> <tr> <td>MIT</td> </tr> <tr> <td>Cambridge, Massachussetts</td> </tr> <tr> <td>1997</td> </tr> </table> <p> </p> </div> </div> <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"><a accesskey="p" href="rms.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="rnd31.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">rms </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top"> rnd31</td> </tr> </table> </div> </body> </html>