<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>rand_scs.c Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.2.15 --> <center> <a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="annotated.html">Data Structures</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Data Fields</a> <a class="qindex" href="globals.html">Globals</a> </center> <hr><h1>rand_scs.c</h1><div class="fragment"><pre>00001 <font class="comment">/*</font> 00002 <font class="comment"> * Author : Defour David</font> 00003 <font class="comment"> * Contact : David.Defour@ens-lyon.fr</font> 00004 <font class="comment"> *</font> 00005 <font class="comment"> * This program is free software; you can redistribute it and/or modify</font> 00006 <font class="comment"> * it under the terms of the GNU Lesser General Public License as published by</font> 00007 <font class="comment"> * the Free Software Foundation; either version 2 of the License, or </font> 00008 <font class="comment"> * (at your option) any later version.</font> 00009 <font class="comment"> * </font> 00010 <font class="comment"> * This program is distributed in the hope that it will be useful,</font> 00011 <font class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</font> 00012 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</font> 00013 <font class="comment"> * GNU General Public License for more details.</font> 00014 <font class="comment"> *</font> 00015 <font class="comment"> * You should have received a copy of the GNU Lesser General Public License</font> 00016 <font class="comment"> * along with this program; if not, write to the Free Software</font> 00017 <font class="comment"> * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. </font> 00018 <font class="comment"> */</font> 00019 <font class="preprocessor">#include <stdlib.h></font> 00020 <font class="preprocessor">#include "<a class="code" href="scs_8h.html">scs.h</a>"</font> 00021 <font class="preprocessor">#include "<a class="code" href="scs__private_8h.html">scs_private.h</a>"</font> 00022 00023 <font class="comment">/*</font> 00024 <font class="comment"> * Return 'sizeof(int)' random bits </font> 00025 <font class="comment"> */</font> 00026 00027 00028 <font class="keywordtype">int</font> rand_val(<font class="keywordtype">void</font>){ 00029 <font class="keywordtype">int</font> val; 00030 <font class="keywordtype">int</font> i; 00031 00032 val = (rand() & 0x000000ff); 00033 <font class="keywordflow">for</font>(i=0; i<(<font class="keyword">sizeof</font>(int)); i++){ 00034 val = val << 8; 00035 val += (rand() & 0x000000ff ); <font class="comment">/* we keep only 8 bits */</font> 00036 } 00037 <font class="keywordflow">return</font> val; 00038 } 00039 00040 00041 <font class="comment">/*</font> 00042 <font class="comment"> * Put into 'result' a scs random number with the index field set</font> 00043 <font class="comment"> * with a value between -expo_max and +expo_max.</font> 00044 <font class="comment"> *</font> 00045 <font class="comment"> * Rem. :</font> 00046 <font class="comment"> * 1) If you want an scs number belonging to double precision floating</font> 00047 <font class="comment"> * point number you must call scs_rand with an expo_max less than 39.</font> 00048 <font class="comment"> * 2) expo_max must be less than RAND_MAX that is usually set a</font> 00049 <font class="comment"> * value greater than 32767</font> 00050 <font class="comment"> */</font> 00051 <font class="keywordtype">void</font> scs_rand(<a class="code" href="structscs.html">scs_ptr</a> result, <font class="keywordtype">int</font> expo_max){ 00052 <font class="keywordtype">int</font> i; 00053 00054 R_EXP = 1; 00055 R_IND = (rand() % (2*expo_max)) - expo_max; 00056 R_SGN = ((2*rand()- RAND_MAX) > 0) ? (-1) : (1); 00057 00058 00059 <font class="keywordflow">for</font>(i=0; i<SCS_NB_WORDS; i++){ 00060 <font class="comment">/* We keep the first SCS_NB_BITS bits of a random value */</font> 00061 R_HW[i] = rand_val() & SCS_MASK_RADIX; 00062 } 00063 } </pre></div><hr><address align="right"><small>Generated on Tue Jun 17 10:15:51 2003 for SCSLib by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.15 </small></address> </body> </html>