<?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>urandom</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="upsamp.html" title="upsamp" /> <link rel="next" href="urd.html" title="urd" /> </head> <body> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center">urandom</th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="upsamp.html">Prev</a> </td> <th width="60%" align="center">Orchestra Opcodes and Operators</th> <td width="20%" align="right"> <a accesskey="n" href="urd.html">Next</a></td> </tr> </table> <hr /> </div> <div class="refentry" title="urandom"> <a id="urandom"></a> <div class="titlepage"></div> <a id="IndexUrandom" class="indexterm"></a> <div class="refnamediv"> <h2> <span class="refentrytitle">urandom</span> </h2> <p>urandom — truly random opcodes with controllable range. </p> </div> <div class="refsect1" title="Description"> <a id="idp49880352"></a> <h2>Description</h2> <p> truly random opcodes with controllable range. These units are for Linux only and use /dev/urandom to construct Csound random values </p> </div> <div class="refsect1" title="Syntax"> <a id="idp49881216"></a> <h2>Syntax</h2> <pre class="synopsis">ax <span class="command"><strong>urandom</strong></span> [imin, imax]</pre> <pre class="synopsis">ix <span class="command"><strong>urandom</strong></span> [imin, imax]</pre> <pre class="synopsis">kx <span class="command"><strong>urandom</strong></span> [imin, imax]</pre> </div> <div class="refsect1" title="Initialization"> <a id="idp49910616"></a> <h2>Initialization</h2> <p> <span class="emphasis"><em>ix</em></span> -- i-rate output value. </p> <p> <span class="emphasis"><em>imin</em></span> -- minimum value of range; defaults to -1. </p> <p> <span class="emphasis"><em>imax</em></span> -- maximum value of range; defaults to +1. </p> <div class="note" title="Notes" style="margin-left: 0.5in; margin-right: 0.5in;"> <table border="0" summary="Note: Notes"> <tr> <td rowspan="2" align="center" valign="top" width="25"> <img alt="[Note]" src="images/note.png" /> </td> <th align="left">Notes</th> </tr> <tr> <td align="left" valign="top"> <p> The algorithm produces 2^64 different possible values which are scaled to fit the range requested. The randomness comes form the usual Linux /dev/urandom method, and there is no guarantee that it will be truly random, but there is a good chance. It does not show any cycles. </p> </td> </tr> </table> </div> </div> <div class="refsect1" title="Performance"> <a id="idp49913784"></a> <h2>Performance</h2> <p> <span class="emphasis"><em>ax</em></span> -- a-rate output value. </p> <p> <span class="emphasis"><em>kx</em></span> -- k-rate output value. </p> </div> <div class="refsect1" title="Examples"> <a id="idp49915112"></a> <h2>Examples</h2> <p> Here is an example of the urandom opcode at a-rate. It uses the file <a class="ulink" href="examples/urandom.csd" target="_top"><em class="citetitle">urandom.csd</em></a>. </p> <div class="example"> <a id="idp49916112"></a> <p class="title"> <strong>Example 910. An example of the urandom opcode at a-rate.</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 rnd31.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">; Create random numbers at a-rate in the range -2 to 2</span> aur <span class="opc">urandom</span> <span class="op">-</span>2, 2 <span class="comment">; Use the random numbers to choose a frequency.</span> afreq <span class="op">=</span> aur <span class="op">*</span> 500 <span class="op">+</span> 100 a1 <span class="opc">oscil</span> 30000, afreq, 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 1 <span class="stamnt">e</span> <span class="csdtag"></CsScore></span> <span class="csdtag"></CsoundSynthesizer></span> </pre> </div> </div> <p><br class="example-break" /> </p> <p> Here is an example of the urandom opcode at k-rate. It uses the file <a class="ulink" href="examples/urandom_krate.csd" target="_top"><em class="citetitle">urandom_krate.csd</em></a>. </p> <div class="example"> <a id="idp49919016"></a> <p class="title"> <strong>Example 911. An example of the urandom opcode at k-rate.</strong> </p> <div class="example-contents"> <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 rnd31_krate.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">; Create random numbers at k-rate in the range -1 to 1 </span> <span class="comment">; with a uniform distribution.</span> k1 <span class="opc">urandom</span> <span class="opc">printks</span> "k1<span class="op">=</span><span class="op">%</span>f\\n", 0.1, k1 <span class="oblock">endin</span> <span class="csdtag"></CsInstruments></span> <span class="csdtag"><CsScore></span> <span class="comment">; Play Instrument #1 for one second.</span> <span class="stamnt">i</span> 1 0 1 <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 include lines like this: </p> <pre class="screen"> k1=0.229850 k1=-0.077047 k1=-0.199339 k1=-0.620577 k1=-0.119447 k1=-0.596258 k1=0.525800 k1=-0.171583 k1=-0.017196 k1=-0.974613 k1=-0.036276 </pre> <p> </p> </div> <div class="refsect1" title="Credits"> <a id="idp49920736"></a> <h2>Credits</h2> <p>Author: John ffitch</p> <p>New in version 5.13</p> </div> </div> <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"><a accesskey="p" href="upsamp.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="urd.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">upsamp </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top"> urd</td> </tr> </table> </div> </body> </html>