<?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[lotto zahlen -&amp;gt; rand() bekomme immer wieder die gleichen zahlen]]></title><description><![CDATA[<p>Hallo, ich habe folgendes Problem:</p>
<p>Ich habe ein kleines C++ Programm, dass durch die Funktion rand() mir Lottozahlen generieren soll.<br />
Aber wenn ich das Programm schließe und wieder öffne, erhalte ich immer die selben Zahlen.<br />
Warum?</p>
<pre><code class="language-cpp">//-------------------------------------------------------------------------
# include &lt;iostream&gt;
# include &lt;stdio.h&gt;
# include &lt;conio.h&gt;
# include &lt;stdlib.h&gt;
# include &lt;time.h&gt;
# include &lt;stdio.h&gt;
# include &lt;string&gt;
# include &lt;algorithm&gt;
# include &lt;iomanip&gt;
using namespace std;
//--------------Stephan Liebig 2006-----------------------------------------------------------------------

# ifdef WIN32
# ifdef __BORLANDC__					
# include &lt;conio.h&gt;						
# else

void clrscr (void) {					
  system (&quot;cls&quot;);
}

void pause (void) {
	system (&quot;PAUSE&quot;);
}

void beenden (void) {
	system (&quot;exit&quot;);
}

# endif
# else /* WIN32 */						
void clrscr(void) { }
# endif

/*
	Das Programm generiert 6 Zahlen von 1 bis 49
*/

const int KugelZahl = 6;
const int MaxZahl = 49;

int main()
{
	int lotto[KugelZahl];
	int i;
	int j;
	int hilf;
	bool neueZahl;

	cout &lt;&lt; &quot;Lottozahlen: 6 aus 49!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;----------------------------------------------------&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Stephan Liebig&quot; &lt;&lt; endl &lt;&lt; endl;

		srand(38); // Mische einmal durch!
		//Ermittle sechs Lottozahlen
		for(i=0; i&lt;KugelZahl; i++)
		{
			// Schleife prüft auf Doppelte
			do
			{
				lotto[i] = rand() % MaxZahl + 1;
				neueZahl = true; //positiv denken!
				//Alle bisherigen Zahlen gegentesten
				for(j=0; j&lt;i; j++)
				{
					if(lotto[j]==lotto[i])
					{
						neueZahl = false; // die gab es schon!
					}
				}
			}while (!neueZahl);
		}
		// Nun werden die Zahlen sortiert (per Bubblesort)
		for(i=KugelZahl-1; i&gt;0; i--)
		{
			for(j=0; j&lt;i; j++)
			{
				if(lotto[j]&gt;lotto[j+1])
				{
					hilf = lotto[j];
					lotto[j] = lotto[j+1];
					lotto[j+1] = hilf;
				}
			}
		}
		//Ausgabe der sortierten Zahlen
		for(i=0; i&lt;KugelZahl; i++)
		{
			cout &lt;&lt; i+1 &lt;&lt; &quot;. Nummer: &quot; &lt;&lt; lotto[i] &lt;&lt; endl;
		}

	getchar();
	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/147620/lotto-zahlen-gt-rand-bekomme-immer-wieder-die-gleichen-zahlen</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Sep 2026 07:36:27 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/147620.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 18 May 2006 15:59:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to lotto zahlen -&amp;gt; rand() bekomme immer wieder die gleichen zahlen on Thu, 18 May 2006 15:59:11 GMT]]></title><description><![CDATA[<p>Hallo, ich habe folgendes Problem:</p>
<p>Ich habe ein kleines C++ Programm, dass durch die Funktion rand() mir Lottozahlen generieren soll.<br />
Aber wenn ich das Programm schließe und wieder öffne, erhalte ich immer die selben Zahlen.<br />
Warum?</p>
<pre><code class="language-cpp">//-------------------------------------------------------------------------
# include &lt;iostream&gt;
# include &lt;stdio.h&gt;
# include &lt;conio.h&gt;
# include &lt;stdlib.h&gt;
# include &lt;time.h&gt;
# include &lt;stdio.h&gt;
# include &lt;string&gt;
# include &lt;algorithm&gt;
# include &lt;iomanip&gt;
using namespace std;
//--------------Stephan Liebig 2006-----------------------------------------------------------------------

# ifdef WIN32
# ifdef __BORLANDC__					
# include &lt;conio.h&gt;						
# else

void clrscr (void) {					
  system (&quot;cls&quot;);
}

void pause (void) {
	system (&quot;PAUSE&quot;);
}

void beenden (void) {
	system (&quot;exit&quot;);
}

# endif
# else /* WIN32 */						
void clrscr(void) { }
# endif

/*
	Das Programm generiert 6 Zahlen von 1 bis 49
*/

const int KugelZahl = 6;
const int MaxZahl = 49;

int main()
{
	int lotto[KugelZahl];
	int i;
	int j;
	int hilf;
	bool neueZahl;

	cout &lt;&lt; &quot;Lottozahlen: 6 aus 49!&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;----------------------------------------------------&quot; &lt;&lt; endl;
	cout &lt;&lt; &quot;Stephan Liebig&quot; &lt;&lt; endl &lt;&lt; endl;

		srand(38); // Mische einmal durch!
		//Ermittle sechs Lottozahlen
		for(i=0; i&lt;KugelZahl; i++)
		{
			// Schleife prüft auf Doppelte
			do
			{
				lotto[i] = rand() % MaxZahl + 1;
				neueZahl = true; //positiv denken!
				//Alle bisherigen Zahlen gegentesten
				for(j=0; j&lt;i; j++)
				{
					if(lotto[j]==lotto[i])
					{
						neueZahl = false; // die gab es schon!
					}
				}
			}while (!neueZahl);
		}
		// Nun werden die Zahlen sortiert (per Bubblesort)
		for(i=KugelZahl-1; i&gt;0; i--)
		{
			for(j=0; j&lt;i; j++)
			{
				if(lotto[j]&gt;lotto[j+1])
				{
					hilf = lotto[j];
					lotto[j] = lotto[j+1];
					lotto[j+1] = hilf;
				}
			}
		}
		//Ausgabe der sortierten Zahlen
		for(i=0; i&lt;KugelZahl; i++)
		{
			cout &lt;&lt; i+1 &lt;&lt; &quot;. Nummer: &quot; &lt;&lt; lotto[i] &lt;&lt; endl;
		}

	getchar();
	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1060285</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1060285</guid><dc:creator><![CDATA[stephan*]]></dc:creator><pubDate>Thu, 18 May 2006 15:59:11 GMT</pubDate></item><item><title><![CDATA[Reply to lotto zahlen -&amp;gt; rand() bekomme immer wieder die gleichen zahlen on Thu, 18 May 2006 16:01:08 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>siehe <a href="http://www.cppreference.com/stdother/srand.html" rel="nofollow">hier</a>.</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1060287</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1060287</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Thu, 18 May 2006 16:01:08 GMT</pubDate></item><item><title><![CDATA[Reply to lotto zahlen -&amp;gt; rand() bekomme immer wieder die gleichen zahlen on Thu, 18 May 2006 16:09:57 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">srand(38); // Mische einmal durch!
</code></pre>
<p>Du mischt nicht!</p>
<pre><code class="language-cpp">#include &lt;time.h&gt;

srand( ( unsigned int ) time( 0 ) );
</code></pre>
<p>sollt's tun.</p>
<p>Greetz, Swordfish</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1060292</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1060292</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Thu, 18 May 2006 16:09:57 GMT</pubDate></item><item><title><![CDATA[Reply to lotto zahlen -&amp;gt; rand() bekomme immer wieder die gleichen zahlen on Thu, 18 May 2006 16:25:59 GMT]]></title><description><![CDATA[<p>Funktioniert! Danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1060314</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1060314</guid><dc:creator><![CDATA[stephan*]]></dc:creator><pubDate>Thu, 18 May 2006 16:25:59 GMT</pubDate></item></channel></rss>