Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Edit</strong> Since the question was edited for C only:</p> <p>This page is pretty helpful: <a href="http://www.geekpedia.com/tutorial39_Random-Number-Generation.html" rel="nofollow">http://www.geekpedia.com/tutorial39_Random-Number-Generation.html</a></p> <pre><code>#include &lt;stdlib.h&gt; #include &lt;stdio.h&gt; #include &lt;time.h&gt; //use this first function to seed the random number generator, //call this before any of the other functions void initrand() { srand((unsigned)(time(0))); } //generates a psuedo-random float between 0.0 and 0.999... float randfloat() { return rand()/(float(RAND_MAX)+1); } //generates a psuedo-random float between 0.0 and max float randfloat(float max) { return randfloat()*max; } //generates a psuedo-random float between min and max float randfloat(float min, float max) { if (min&gt;max) return randfloat()*(min-max)+max; else return randfloat()*(max-min)+min; } //generates a psuedo-random double between 0.0 and 0.999... double randdouble() { return rand()/(double(RAND_MAX)+1); } //generates a psuedo-random double between 0.0 and max double randdouble(double max) { return randdouble()*max; } //generates a psuedo-random double between min and max double randdouble(double min, double max) { if (min&gt;max) return randdouble()*(min-max)+max; else return randdouble()*(max-min)+min; } int main() { for (int i=0; i&lt;10; i++) printf("%f\n", randdouble(-1,3)); } </code></pre> <h2>Output sample:</h2> <pre><code>2.360751 0.577532 2.132397 2.193760 2.646589 -0.209795 0.340891 2.072918 0.111099 1.215880 </code></pre> <p>(note the range: -1..3)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload