<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Rand() bringt mich noch um...]]></title><description><![CDATA[<p>guten abend allerseits <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>so kurz und schmerzlos:<br />
ich habe irgendwas falsch gemacht,weswegen jetzt rand() nicht mehr funktioniert..</p>
<pre><code class="language-cpp">srand(time(0));
int summe = rand() % 20;
</code></pre>
<p>Wenn ich das dann mit cout aufrufe,kommt ein seltsames Ergebnis bis zu 10 000 heraus <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>so schaut des voll aus:</p>
<pre><code class="language-cpp">srand(time(0));
int summe = rand() % 20;//20,17,1,14,..blabla
cout&lt;&lt;summe;
</code></pre>
<p>Ich hoffe,ihr könnt mir auf die Beine helfen *g* <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/160959/rand-bringt-mich-noch-um</link><generator>RSS for Node</generator><lastBuildDate>Fri, 11 Sep 2026 16:56:18 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/160959.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 01 Oct 2006 18:28:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Rand() bringt mich noch um... on Sun, 01 Oct 2006 18:28:30 GMT]]></title><description><![CDATA[<p>guten abend allerseits <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>so kurz und schmerzlos:<br />
ich habe irgendwas falsch gemacht,weswegen jetzt rand() nicht mehr funktioniert..</p>
<pre><code class="language-cpp">srand(time(0));
int summe = rand() % 20;
</code></pre>
<p>Wenn ich das dann mit cout aufrufe,kommt ein seltsames Ergebnis bis zu 10 000 heraus <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>so schaut des voll aus:</p>
<pre><code class="language-cpp">srand(time(0));
int summe = rand() % 20;//20,17,1,14,..blabla
cout&lt;&lt;summe;
</code></pre>
<p>Ich hoffe,ihr könnt mir auf die Beine helfen *g* <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1147565</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1147565</guid><dc:creator><![CDATA[Primer]]></dc:creator><pubDate>Sun, 01 Oct 2006 18:28:30 GMT</pubDate></item><item><title><![CDATA[Reply to Rand() bringt mich noch um... on Sun, 01 Oct 2006 18:52:07 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>kann ich mir nicht vorstellen, das bei genau diesem Code du 10000 als Ergebnis bekommst.</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1147573</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1147573</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Sun, 01 Oct 2006 18:52:07 GMT</pubDate></item><item><title><![CDATA[Reply to Rand() bringt mich noch um... on Sun, 01 Oct 2006 18:57:42 GMT]]></title><description><![CDATA[<p>akari schrieb:</p>
<blockquote>
<p>Hallo</p>
<p>kann ich mir nicht vorstellen, das bei genau diesem Code du 10000 als Ergebnis bekommst.</p>
<p>bis bald<br />
akari</p>
</blockquote>
<p>versuch es bitte selbst,ich bekommen nähmlich 1010,1587,1000,...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1147576</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1147576</guid><dc:creator><![CDATA[Primer]]></dc:creator><pubDate>Sun, 01 Oct 2006 18:57:42 GMT</pubDate></item><item><title><![CDATA[Reply to Rand() bringt mich noch um... on Sun, 01 Oct 2006 19:10:15 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>einerseits bin ich mir dabei sehr sicher, andereseits hab ich auch wie erwartet beim Test dieses Codes nur Zahlen zwischen 0 und 19 bekommen</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

int main()
{
  srand(time(0));
  for (int lv = 0; lv &lt; 100; lv++)
  {
    int summe = rand() % 20;//20,17,1,14,..blabla
    std::cout&lt;&lt;summe &lt;&lt; std::endl;
  }
}
</code></pre>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1147583</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1147583</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Sun, 01 Oct 2006 19:10:15 GMT</pubDate></item><item><title><![CDATA[Reply to Rand() bringt mich noch um... on Sun, 01 Oct 2006 19:14:55 GMT]]></title><description><![CDATA[<p>%20 heißt ja der Rest, wenn ich die Zahl durch 20 Teile, also können nur Zahlen zwischen 0 und 19 rauskommen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1147585</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1147585</guid><dc:creator><![CDATA[Schildkroete]]></dc:creator><pubDate>Sun, 01 Oct 2006 19:14:55 GMT</pubDate></item><item><title><![CDATA[Reply to Rand() bringt mich noch um... on Mon, 02 Oct 2006 05:43:16 GMT]]></title><description><![CDATA[<p>Wieso gibts immer noch Leute dir im Bezug auf <em>rand()</em> mit Modulo arbeiten? Lasst das doch endlich mal...</p>
<p>grüß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1147705</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1147705</guid><dc:creator><![CDATA[David_pb]]></dc:creator><pubDate>Mon, 02 Oct 2006 05:43:16 GMT</pubDate></item><item><title><![CDATA[Reply to Rand() bringt mich noch um... on Mon, 02 Oct 2006 06:58:36 GMT]]></title><description><![CDATA[<p>David_pb schrieb:</p>
<blockquote>
<p>Wieso gibts immer noch Leute dir im Bezug auf <em>rand()</em> mit Modulo arbeiten? Lasst das doch endlich mal...</p>
<p>grüß</p>
</blockquote>
<p>Wieso nicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1147723</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1147723</guid><dc:creator><![CDATA[DarthZiu]]></dc:creator><pubDate>Mon, 02 Oct 2006 06:58:36 GMT</pubDate></item><item><title><![CDATA[Reply to Rand() bringt mich noch um... on Mon, 02 Oct 2006 08:18:29 GMT]]></title><description><![CDATA[<p>Weil du mit Modulo die &quot;Breite&quot; der möglichen Zufallszahlen von 0..RAND_MAX auf 0..RANGE begrenzt.</p>
<p>grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1147760</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1147760</guid><dc:creator><![CDATA[David_pb]]></dc:creator><pubDate>Mon, 02 Oct 2006 08:18:29 GMT</pubDate></item><item><title><![CDATA[Reply to Rand() bringt mich noch um... on Mon, 02 Oct 2006 08:23:45 GMT]]></title><description><![CDATA[<p>Ehrlich?</p>
<p>Was denkst du denn, ist sonst der Zweck?</p>
<p>Primer hatte in einem anderen Thread gefragt, wie man die Zufallszahlen begrenzt, daher schreibt er hier 'rand() % 20'.</p>
<p>Ich kenne eigentlich so gut wie keine Anwendung, in der die volle Breite von Zufallszahlen erwünscht ist. Man muss den Bereich immer abgrenzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1147761</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1147761</guid><dc:creator><![CDATA[DarthZiu]]></dc:creator><pubDate>Mon, 02 Oct 2006 08:23:45 GMT</pubDate></item><item><title><![CDATA[Reply to Rand() bringt mich noch um... on Mon, 02 Oct 2006 09:13:06 GMT]]></title><description><![CDATA[<p>DarthZiu schrieb:</p>
<blockquote>
<p>Ehrlich?</p>
<p>Was denkst du denn, ist sonst der Zweck?</p>
<p>Primer hatte in einem anderen Thread gefragt, wie man die Zufallszahlen begrenzt, daher schreibt er hier 'rand() % 20'.</p>
<p>Ich kenne eigentlich so gut wie keine Anwendung, in der die volle Breite von Zufallszahlen erwünscht ist. Man muss den Bereich immer abgrenzen.</p>
</blockquote>
<p>Du verstehst das immer noch nicht oder?</p>
<p>man rand() schrieb:</p>
<blockquote>
<p>&quot;If you want to generate a random integer between 1<br />
and 10, you should always do it by using high-order<br />
bits, as in</p>
<p>j=1+(int) (10.0*rand()/(RAND_MAX+1.0));</p>
<p>and never by anything resembling</p>
<p>j=1+(rand() % 10);</p>
<p>(which uses lower-order bits).&quot;</p>
</blockquote>
<p>Und hier:<br />
<a href="http://www.azillionmonkeys.com/qed/random.html" rel="nofollow">http://www.azillionmonkeys.com/qed/random.html</a><br />
<a href="http://mandrill.fuxx0r.net/c++/faq:no_rand_modulo" rel="nofollow">http://mandrill.fuxx0r.net/c++/faq:no_rand_modulo</a></p>
<p>Und unzählige weitere Links die per Google gefunden werden können.</p>
<p>Im Klartext. Mit Modulo wird die wahrscheinlichkeit vergrößert das Zahlen aus einem bestimmen Bereich öfter auftreten. Und das ist tatsächlich nicht Sinn von <strong>Zufalls</strong>zahlen.</p>
<p>grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1147787</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1147787</guid><dc:creator><![CDATA[David_pb]]></dc:creator><pubDate>Mon, 02 Oct 2006 09:13:06 GMT</pubDate></item><item><title><![CDATA[Reply to Rand() bringt mich noch um... on Mon, 02 Oct 2006 10:09:09 GMT]]></title><description><![CDATA[<p>David_pb schrieb:</p>
<blockquote>
<p><a href="http://mandrill.fuxx0r.net/c++/faq:no_rand_modulo" rel="nofollow">http://mandrill.fuxx0r.net/c++/faq:no_rand_modulo</a></p>
</blockquote>
<p>Okay, ehrlich gesagt kannte ich das noch nicht und lass es für eine hohe obere Schranke des Intervalls gelten.</p>
<p>Aber für Zufallszahlen in einem Bereich wie [0,20] kann man nach dem Beispiel oben genauso gut die Variante &quot;rand()%OBERE_GRENZE-1&quot; benutzen:</p>
<p>Denn (wir nehmen mal wie im Beispiel RAND_MAX als 32767) und unser Intervall [0,20]:</p>
<pre><code>32767 / 20 = 1638 Rest 7

Heißt also, dass nur bei den letzten 7 von 32767 möglichen Zufallszahlen das Intervall von [0,7] öfters auftreten würde, was ein Wahrscheinlichkeitsverhältnis von 

1/1638 zu 1/1639 

entspricht.
</code></pre>
<p>Wenn ich mich nicht verrechnet habe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Aber ist auf jeden Fall interessant zu wissen. Wieder was gelernt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1147832</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1147832</guid><dc:creator><![CDATA[DarthZiu]]></dc:creator><pubDate>Mon, 02 Oct 2006 10:09:09 GMT</pubDate></item></channel></rss>