<?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[Ist zwar die Sache mit den Zufall aber nicht so wirklich!]]></title><description><![CDATA[<p>Also ich hab folgendes Programm!</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;cstdlib&gt;
#include &lt;ctime&gt; 
using namespace std;

int main()
{
    int Teilnehmeranzahl;
    string Name[10];
    cout&lt;&lt;&quot;Wieviel Personen nehmen teil?\n&quot;;
    cin&gt;&gt;Teilnehmeranzahl;
    for(int loop=0;loop&lt;Teilnehmeranzahl;loop++)
    {
            cout&lt;&lt;&quot;\nGeben Sie den Namen des &quot;&lt;&lt;loop+1&lt;&lt;&quot; Teilnehmer ein!\n&quot;;
            cin&gt;&gt;Name[loop];
    }
    srand( (unsigned)time( NULL ) );
    cout&lt;&lt;&quot;\nEs treten an!\n&quot;;
    for(int loop1=0;loop1&lt;Teilnehmeranzahl/2;loop1++)
    {
            cout&lt;&lt;Name[rand()%Teilnehmeranzahl]&lt;&lt;&quot; vs. &quot;&lt;&lt;Name[rand()%Teilnehmeranzahl]&lt;&lt;&quot;\n&quot;;
            cout&lt;&lt;&quot;Referee: &quot;&lt;&lt;Name[rand()%Teilnehmeranzahl]&lt;&lt;&quot;\n&quot;;
    }
    system(&quot;Pause&quot;);
}
</code></pre>
<p>Nun ist es so das manche Namen doppelt oder dreifach ausgegeben werden! Wie kann ich das verhindern???</p>
<p>MfG</p>
<p>Sascha081088</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/131502/ist-zwar-die-sache-mit-den-zufall-aber-nicht-so-wirklich</link><generator>RSS for Node</generator><lastBuildDate>Thu, 27 Aug 2026 05:02:29 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/131502.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 04 Jan 2006 00:12:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Ist zwar die Sache mit den Zufall aber nicht so wirklich! on Wed, 04 Jan 2006 00:12:00 GMT]]></title><description><![CDATA[<p>Also ich hab folgendes Programm!</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;cstdlib&gt;
#include &lt;ctime&gt; 
using namespace std;

int main()
{
    int Teilnehmeranzahl;
    string Name[10];
    cout&lt;&lt;&quot;Wieviel Personen nehmen teil?\n&quot;;
    cin&gt;&gt;Teilnehmeranzahl;
    for(int loop=0;loop&lt;Teilnehmeranzahl;loop++)
    {
            cout&lt;&lt;&quot;\nGeben Sie den Namen des &quot;&lt;&lt;loop+1&lt;&lt;&quot; Teilnehmer ein!\n&quot;;
            cin&gt;&gt;Name[loop];
    }
    srand( (unsigned)time( NULL ) );
    cout&lt;&lt;&quot;\nEs treten an!\n&quot;;
    for(int loop1=0;loop1&lt;Teilnehmeranzahl/2;loop1++)
    {
            cout&lt;&lt;Name[rand()%Teilnehmeranzahl]&lt;&lt;&quot; vs. &quot;&lt;&lt;Name[rand()%Teilnehmeranzahl]&lt;&lt;&quot;\n&quot;;
            cout&lt;&lt;&quot;Referee: &quot;&lt;&lt;Name[rand()%Teilnehmeranzahl]&lt;&lt;&quot;\n&quot;;
    }
    system(&quot;Pause&quot;);
}
</code></pre>
<p>Nun ist es so das manche Namen doppelt oder dreifach ausgegeben werden! Wie kann ich das verhindern???</p>
<p>MfG</p>
<p>Sascha081088</p>
]]></description><link>https://www.c-plusplus.net/forum/post/956221</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/956221</guid><dc:creator><![CDATA[Sascha081088]]></dc:creator><pubDate>Wed, 04 Jan 2006 00:12:00 GMT</pubDate></item><item><title><![CDATA[Reply to Ist zwar die Sache mit den Zufall aber nicht so wirklich! on Wed, 04 Jan 2006 01:06:54 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Wie wär's, wenn du z.B. Folgendes machst:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;cstdlib&gt;
#include &lt;ctime&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt; // wird benötigt für random_shuffle.
using namespace std;

int main()
{
    int Teilnehmeranzahl;
    string Name[10];
    cout&lt;&lt;&quot;Wieviel Personen nehmen teil?\n&quot;;
    cin&gt;&gt;Teilnehmeranzahl;
    for(int loop=0;loop&lt;Teilnehmeranzahl;loop++)
    {
            cout&lt;&lt;&quot;\nGeben Sie den Namen des &quot;&lt;&lt;loop+1&lt;&lt;&quot; Teilnehmer ein!\n&quot;;
            cin&gt;&gt;Name[loop];
    }
    cout&lt;&lt;&quot;\nEs treten an!\n&quot;;

    // Jedem Spieler eine eindeutige ID geben.
    vector&lt;size_t&gt; player_id(Teilnehmeranzahl);
    for(size_t i = 0; i &lt; player_id.size(); ++i)
        player_id[i] = i;

    random_shuffle(player_id.begin(), player_id.end()); // diese IDS tauschen.

    for(int loop1=0;loop1 &lt; Teilnehmeranzahl - 2; loop1 += 3)
    {
            // Spieler mit den jeweiligen IDs gegeneinander antreten lassen.
            cout&lt;&lt;Name[player_id[loop1&rsqb;&rsqb;&lt;&lt;&quot; vs. &quot;&lt;&lt;Name[player_id[loop1 + 1&rsqb;&rsqb;&lt;&lt;&quot;\n&quot;;
            cout&lt;&lt;&quot;Referee: &quot;&lt;&lt;Name[player_id[loop1 + 2]&lt;&lt;&quot;\n&quot;;
    }
    system(&quot;Pause&quot;);
}
</code></pre>
<p>Bzg. random_shuffle siehe <a href="http://www.cppreference.com/cppalgorithm/random_shuffle.html" rel="nofollow">hier</a>.</p>
<p>Eine erweiterte Fehlerüberprüfung und die Verschönerung dieser hingehackten Variante überlass ich dir :).</p>
<p>btw:<br />
- du musst deine Zählvariablen nicht unterschiedlich benennen. (Sie sind in der jeweiligen Schleife lokal!).<br />
- system(&quot;Pause&quot;) ist bäh ;).</p>
<p>Gruß Caipi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/956235</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/956235</guid><dc:creator><![CDATA[Caipi]]></dc:creator><pubDate>Wed, 04 Jan 2006 01:06:54 GMT</pubDate></item><item><title><![CDATA[Reply to Ist zwar die Sache mit den Zufall aber nicht so wirklich! on Wed, 04 Jan 2006 12:08:27 GMT]]></title><description><![CDATA[<p>oder ganz simpel mit 2 dim array:<br />
( im 2.ten feld einfach abhaken, ob der spieler schon gezogen wurde )</p>
<p>allerdings musst du dir das mit dem schiedsrichter noch ueberlegen... <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>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;

using namespace std;

    string Name[10][2];
    int Teilnehmeranzahl;

string gezogen() {
   int i=rand()%Teilnehmeranzahl;
   while (Name[i][1]&gt;&quot;&quot; ) 
      i=rand()%Teilnehmeranzahl;

   Name[i][1]=&quot;X&quot;;  //egal was&gt;&quot;&quot; 
   return    Name[i][0];
}

int main()
{
    cout&lt;&lt;&quot;Wieviel Personen nehmen teil?\n&quot;;
    cin&gt;&gt;Teilnehmeranzahl;
    for(int loop=0;loop&lt;Teilnehmeranzahl;loop++)
    {
            cout&lt;&lt;&quot;\nGeben Sie den Namen des &quot;&lt;&lt;loop+1&lt;&lt;&quot; Teilnehmer ein!\n&quot;;
            cin&gt;&gt;Name[loop][0];
    }
    srand( (unsigned)time( NULL ) );
    cout&lt;&lt;&quot;\nEs treten an!\n&quot;;
    for(int loop1=0;loop1&lt;Teilnehmeranzahl/2;loop1++)
    {
            cout&lt;&lt;gezogen()&lt;&lt;&quot; vs. &quot;&lt;&lt;gezogen()&lt;&lt;&quot;\n&quot;;
      // cout&lt;&lt;&quot;Referee: &quot;&lt;&lt;Name[rand()%Teilnehmeranzahl][0]&lt;&lt;&quot;\n&quot;;
    }
    system(&quot;Pause&quot;);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/956496</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/956496</guid><dc:creator><![CDATA[kermit1]]></dc:creator><pubDate>Wed, 04 Jan 2006 12:08:27 GMT</pubDate></item><item><title><![CDATA[Reply to Ist zwar die Sache mit den Zufall aber nicht so wirklich! on Wed, 04 Jan 2006 19:19:15 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>wenn man den Vorschlag von Caipi (random_shuffle) anwendet, kommt man auf eine ganz einfache Lösung:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;cstdlib&gt;
#include &lt;ctime&gt;
#include &lt;algorithm&gt;

int main()
{
	std::srand( (unsigned)std::time( NULL ) );

	size_t anzahl = 0;
	std::cout &lt;&lt; &quot;Bitte die Anzahl der Spieler eingeben:&quot; &lt;&lt; std::endl;
	std::cin &gt;&gt; anzahl;
	std::vector&lt;std::string&gt; spieler;
	for(std::size_t i = 0;i &lt; anzahl;++i)
	{
		std::cout &lt;&lt; &quot;Namen fuer &quot; &lt;&lt; i+1 &lt;&lt; &quot; . Spieler angeben:&quot; &lt;&lt; std::endl;
		std::string name = &quot;&quot;;
		std::cin &gt;&gt; name;
		spieler.push_back(name);
	}

	std::random_shuffle(spieler.begin(), spieler.end());

	for(int i = 0;i &lt; anzahl;i += 2)
	{
		std::cout &lt;&lt; spieler[i] &lt;&lt; &quot; vs. &quot; &lt;&lt; spieler[i + 1] &lt;&lt; std::endl;
	}

	std::system(&quot;pause&quot;);

	return 0;
}
</code></pre>
<p>Viel Spaß beim Ausprobieren. :xmas1:</p>
]]></description><link>https://www.c-plusplus.net/forum/post/957046</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/957046</guid><dc:creator><![CDATA[pcmoritz]]></dc:creator><pubDate>Wed, 04 Jan 2006 19:19:15 GMT</pubDate></item></channel></rss>