<?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[2 verschiedene Zufallszahlen erzeugen]]></title><description><![CDATA[<p>Hi,<br />
Ich habe mal eine Frage, ich möchte 2 Zufallszahlen erzeugen, aber verhindern dass es zweimal die selbe Zahl wird.<br />
Ich hätte mir eine Realisierung mithilfe von if-Abfragen vorgestellt.<br />
Hätte jemand einen Lösungsansatz.<br />
Danke im Voraus <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/328565/2-verschiedene-zufallszahlen-erzeugen</link><generator>RSS for Node</generator><lastBuildDate>Tue, 07 Jul 2026 13:07:06 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/328565.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 16 Oct 2014 15:41:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to 2 verschiedene Zufallszahlen erzeugen on Thu, 16 Oct 2014 15:41:07 GMT]]></title><description><![CDATA[<p>Hi,<br />
Ich habe mal eine Frage, ich möchte 2 Zufallszahlen erzeugen, aber verhindern dass es zweimal die selbe Zahl wird.<br />
Ich hätte mir eine Realisierung mithilfe von if-Abfragen vorgestellt.<br />
Hätte jemand einen Lösungsansatz.<br />
Danke im Voraus <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422509</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422509</guid><dc:creator><![CDATA[C++Developer2000]]></dc:creator><pubDate>Thu, 16 Oct 2014 15:41:07 GMT</pubDate></item><item><title><![CDATA[Reply to 2 verschiedene Zufallszahlen erzeugen on Thu, 16 Oct 2014 15:41:56 GMT]]></title><description><![CDATA[<p>(Triviale Aufgabe aber) was hast du denn schon bis jetzt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422510</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422510</guid><dc:creator><![CDATA[hanstroll123]]></dc:creator><pubDate>Thu, 16 Oct 2014 15:41:56 GMT</pubDate></item><item><title><![CDATA[Reply to 2 verschiedene Zufallszahlen erzeugen on Thu, 16 Oct 2014 15:54:41 GMT]]></title><description><![CDATA[<p>C++Developer2000 schrieb:</p>
<blockquote>
<p>Ich hätte mir eine Realisierung mithilfe von if-Abfragen vorgestellt.<br />
Hätte jemand einen Lösungsansatz.</p>
</blockquote>
<p>Du hast doch selber gerade einen genannt. <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2422514</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422514</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Thu, 16 Oct 2014 15:54:41 GMT</pubDate></item><item><title><![CDATA[Reply to 2 verschiedene Zufallszahlen erzeugen on Thu, 16 Oct 2014 16:01:25 GMT]]></title><description><![CDATA[<p>hanstroll123 schrieb:</p>
<blockquote>
<p>(Triviale Aufgabe aber) was hast du denn schon bis jetzt?</p>
</blockquote>
<p>Danke für die schnelle Antwort<br />
Das hier:<br />
Aber irgendwie funktioniert es nicht.<br />
srand (time(NULL));<br />
int zahl;<br />
int zahl2;<br />
zahl = rand() % 100;<br />
zahl2= rand()%100;<br />
if(zahl==zahl2)<br />
{<br />
do{<br />
zahl= rand() % 100;<br />
zahl2= rand() % 100;</p>
<p>}while(zahl==zahl2);</p>
<p>}</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422517</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422517</guid><dc:creator><![CDATA[C++Developer2000]]></dc:creator><pubDate>Thu, 16 Oct 2014 16:01:25 GMT</pubDate></item><item><title><![CDATA[Reply to 2 verschiedene Zufallszahlen erzeugen on Thu, 16 Oct 2014 16:09:51 GMT]]></title><description><![CDATA[<p>Was heißt denn &quot;irgendwie funktioniert es nicht&quot; genau?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422518</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422518</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Thu, 16 Oct 2014 16:09:51 GMT</pubDate></item><item><title><![CDATA[Reply to 2 verschiedene Zufallszahlen erzeugen on Thu, 16 Oct 2014 16:12:43 GMT]]></title><description><![CDATA[<p>Das Ergebnis sind sehr häufig 2 gleiche Zahlen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422519</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422519</guid><dc:creator><![CDATA[C++Developer2000]]></dc:creator><pubDate>Thu, 16 Oct 2014 16:12:43 GMT</pubDate></item><item><title><![CDATA[Reply to 2 verschiedene Zufallszahlen erzeugen on Thu, 16 Oct 2014 16:38:29 GMT]]></title><description><![CDATA[<p>Schau dir noch mal die while Schleife an...</p>
<pre><code>}while(zahl==zahl2); //solange bis zahl genau das gleiche ist wie zahl2
}while(zahl!=zahl2); //solange bis zahl etwas anderes ist wie zahl2
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2422522</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422522</guid><dc:creator><![CDATA[dasmitleid]]></dc:creator><pubDate>Thu, 16 Oct 2014 16:38:29 GMT</pubDate></item><item><title><![CDATA[Reply to 2 verschiedene Zufallszahlen erzeugen on Thu, 16 Oct 2014 17:10:20 GMT]]></title><description><![CDATA[<p>C++Developer2000 schrieb:</p>
<blockquote>
<p>Das Ergebnis sind sehr häufig 2 gleiche Zahlen.</p>
</blockquote>
<p>Das kann nicht sein. Die Schleife wird betreten, wenn die Zahlen gleich sind, und sie läuft solange sie gleich sind.</p>
<p>Es wäre übrigens bedeutend einfacher, nur die zweite Zahl neu zu würfeln anstatt immer wieder alle beide.</p>
<p>dasmitleid schrieb:</p>
<blockquote>
<pre><code>}while(zahl==zahl2); //solange bis zahl genau das gleiche ist wie zahl2
}while(zahl!=zahl2); //solange bis zahl etwas anderes ist wie zahl2
</code></pre>
</blockquote>
<p>Es ist genau andersrum.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2422524</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422524</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Thu, 16 Oct 2014 17:10:20 GMT</pubDate></item><item><title><![CDATA[Reply to 2 verschiedene Zufallszahlen erzeugen on Thu, 16 Oct 2014 19:21:34 GMT]]></title><description><![CDATA[<p>Mit nur 2 Zahlen könnte es auch direkter gehen, wenn ich mich nicht irre.</p>
<pre><code>int a=rand()%100;
	int b=rand()%99;
	if(b&gt;=a) ++b;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2422537</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2422537</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Thu, 16 Oct 2014 19:21:34 GMT</pubDate></item><item><title><![CDATA[Reply to 2 verschiedene Zufallszahlen erzeugen on Mon, 20 Oct 2014 18:18:23 GMT]]></title><description><![CDATA[<p>warum erhöhst du b um eins wenn es schon größer ist als a?<br />
Zudem befürchte ich das da der Zufall weniger zufällig wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2423044</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2423044</guid><dc:creator><![CDATA[Dudeldu]]></dc:creator><pubDate>Mon, 20 Oct 2014 18:18:23 GMT</pubDate></item><item><title><![CDATA[Reply to 2 verschiedene Zufallszahlen erzeugen on Mon, 20 Oct 2014 18:24:16 GMT]]></title><description><![CDATA[<p>Dudeldu schrieb:</p>
<blockquote>
<p>warum erhöhst du b um eins wenn es schon größer ist als a?<br />
Zudem befürchte ich das da der Zufall weniger zufällig wird.</p>
</blockquote>
<p>Und Deine Befürchtung beruht auf welcher Überlegung?</p>
<p>Bzw. welche Gedanken hast Du Dir dazu gemacht? Mal einen Entscheidungsbaum aufgezeichnet? Irgendwas?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2423046</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2423046</guid><dc:creator><![CDATA[Furble Wurble]]></dc:creator><pubDate>Mon, 20 Oct 2014 18:24:16 GMT</pubDate></item><item><title><![CDATA[Reply to 2 verschiedene Zufallszahlen erzeugen on Mon, 20 Oct 2014 18:28:25 GMT]]></title><description><![CDATA[<p>a wird gleichverteilt aus {0, ..., 99} ausgewählt, b gleichverteilt aus {0, ..., 99} \ {a}.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2423049</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2423049</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Mon, 20 Oct 2014 18:28:25 GMT</pubDate></item><item><title><![CDATA[Reply to 2 verschiedene Zufallszahlen erzeugen on Mon, 20 Oct 2014 18:43:16 GMT]]></title><description><![CDATA[<p>Dudeldu schrieb:</p>
<blockquote>
<p>warum erhöhst du b um eins wenn es schon größer ist als a?<br />
Zudem befürchte ich das da der Zufall weniger zufällig wird.</p>
</blockquote>
<p>nicht &quot;größer&quot; sondern &quot;größer oder gleich&quot;.</p>
<p>Vielleicht magste dieses Verfahren mehr?</p>
<pre><code>int a=rand()%100;
int b=rand()%99;
if(b==a) b=99;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2423051</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2423051</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Mon, 20 Oct 2014 18:43:16 GMT</pubDate></item></channel></rss>