<?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[Zufallszahl ist immer die gleiche]]></title><description><![CDATA[<p>hallo,</p>
<p>ich versuche ein Würfelspiel zu basteln, und habe 6 Würfel.<br />
Bei einem Klick auf den Button Würfeln, wird die funktion wuerfeln() aufgerufen.<br />
Leider bekomme ich immer die gleichen Zahlen angezeigt:</p>
<pre><code class="language-cpp">int getzahl() {
        randomize();
        srand(time(NULL));
        randomize();
        int zahl = random(5)+1;
        return zahl;
}

int wuerfeln() {
        if(Form1-&gt;wuerfel1-&gt;Enabled == true) {
                Form1-&gt;wuerfel1-&gt;Glyph-&gt;LoadFromFile(AnsiString(getzahl())+&quot;.bmp&quot;);
        }
        Application-&gt;ProcessMessages();
        if(Form1-&gt;wuerfel2-&gt;Enabled == true) {
                Form1-&gt;wuerfel2-&gt;Glyph-&gt;LoadFromFile(AnsiString(getzahl())+&quot;.bmp&quot;);
        }
        randomize();
        if(Form1-&gt;wuerfel3-&gt;Enabled == true) {
                Form1-&gt;wuerfel3-&gt;Glyph-&gt;LoadFromFile(AnsiString(getzahl())+&quot;.bmp&quot;);
        }
        randomize();
        if(Form1-&gt;wuerfel4-&gt;Enabled == true) {
                Form1-&gt;wuerfel4-&gt;Glyph-&gt;LoadFromFile(AnsiString(getzahl())+&quot;.bmp&quot;);
        }
        randomize();
        if(Form1-&gt;wuerfel5-&gt;Enabled == true) {
                Form1-&gt;wuerfel5-&gt;Glyph-&gt;LoadFromFile(AnsiString(getzahl())+&quot;.bmp&quot;);
        }
        randomize();
        if(Form1-&gt;wuerfel6-&gt;Enabled == true) {
                Form1-&gt;wuerfel6-&gt;Glyph-&gt;LoadFromFile(AnsiString(getzahl())+&quot;.bmp&quot;);
        }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/205071/zufallszahl-ist-immer-die-gleiche</link><generator>RSS for Node</generator><lastBuildDate>Wed, 19 Aug 2026 16:11:51 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/205071.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 10 Feb 2008 09:45:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Zufallszahl ist immer die gleiche on Sun, 10 Feb 2008 09:45:37 GMT]]></title><description><![CDATA[<p>hallo,</p>
<p>ich versuche ein Würfelspiel zu basteln, und habe 6 Würfel.<br />
Bei einem Klick auf den Button Würfeln, wird die funktion wuerfeln() aufgerufen.<br />
Leider bekomme ich immer die gleichen Zahlen angezeigt:</p>
<pre><code class="language-cpp">int getzahl() {
        randomize();
        srand(time(NULL));
        randomize();
        int zahl = random(5)+1;
        return zahl;
}

int wuerfeln() {
        if(Form1-&gt;wuerfel1-&gt;Enabled == true) {
                Form1-&gt;wuerfel1-&gt;Glyph-&gt;LoadFromFile(AnsiString(getzahl())+&quot;.bmp&quot;);
        }
        Application-&gt;ProcessMessages();
        if(Form1-&gt;wuerfel2-&gt;Enabled == true) {
                Form1-&gt;wuerfel2-&gt;Glyph-&gt;LoadFromFile(AnsiString(getzahl())+&quot;.bmp&quot;);
        }
        randomize();
        if(Form1-&gt;wuerfel3-&gt;Enabled == true) {
                Form1-&gt;wuerfel3-&gt;Glyph-&gt;LoadFromFile(AnsiString(getzahl())+&quot;.bmp&quot;);
        }
        randomize();
        if(Form1-&gt;wuerfel4-&gt;Enabled == true) {
                Form1-&gt;wuerfel4-&gt;Glyph-&gt;LoadFromFile(AnsiString(getzahl())+&quot;.bmp&quot;);
        }
        randomize();
        if(Form1-&gt;wuerfel5-&gt;Enabled == true) {
                Form1-&gt;wuerfel5-&gt;Glyph-&gt;LoadFromFile(AnsiString(getzahl())+&quot;.bmp&quot;);
        }
        randomize();
        if(Form1-&gt;wuerfel6-&gt;Enabled == true) {
                Form1-&gt;wuerfel6-&gt;Glyph-&gt;LoadFromFile(AnsiString(getzahl())+&quot;.bmp&quot;);
        }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1452891</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1452891</guid><dc:creator><![CDATA[random123456]]></dc:creator><pubDate>Sun, 10 Feb 2008 09:45:37 GMT</pubDate></item><item><title><![CDATA[Reply to Zufallszahl ist immer die gleiche on Sun, 10 Feb 2008 10:22:26 GMT]]></title><description><![CDATA[<p>Das sollte funktionieren:</p>
<pre><code class="language-cpp">int getzahl() {
        Randomize();
        int zahl = random(5)+1;
        return zahl;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1452906</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1452906</guid><dc:creator><![CDATA[Rostfrei**]]></dc:creator><pubDate>Sun, 10 Feb 2008 10:22:26 GMT</pubDate></item><item><title><![CDATA[Reply to Zufallszahl ist immer die gleiche on Sun, 10 Feb 2008 11:04:06 GMT]]></title><description><![CDATA[<p>Ja, fast, nun sind die ersten beiden gleich, und die letzten vier auch, z.B:</p>
<p>1, 1<br />
und<br />
4, 4, 4, 4</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1452917</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1452917</guid><dc:creator><![CDATA[random123456]]></dc:creator><pubDate>Sun, 10 Feb 2008 11:04:06 GMT</pubDate></item><item><title><![CDATA[Reply to Zufallszahl ist immer die gleiche on Sun, 10 Feb 2008 11:27:24 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Das Randomize() darf nur genau einmal pro Programm ausgeführt werden, nicht jedesmal wenn eine Zufallszahl gezogen wird! Und ich glaube nicht das Randomize und random zusammengehören, vermutlich werden hier zwei verschiedene generatoren durcheinandergeworfen. Schau in die BCB-Hilfe welche VCL-Ziehungsfunktion zu Randomize gehört. Oder ins Magazin hier im Forum, da ist ein ganzer Artikel zu Zufallszahlen auf reiner C++ Basis.</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1452928</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1452928</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Sun, 10 Feb 2008 11:27:24 GMT</pubDate></item><item><title><![CDATA[Reply to Zufallszahl ist immer die gleiche on Sun, 10 Feb 2008 11:48:34 GMT]]></title><description><![CDATA[<p>Ok, das Random wird nun bei OnCreate ausgeführt, aber das Problem besteht immernoch</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1452934</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1452934</guid><dc:creator><![CDATA[random123456]]></dc:creator><pubDate>Sun, 10 Feb 2008 11:48:34 GMT</pubDate></item><item><title><![CDATA[Reply to Zufallszahl ist immer die gleiche on Sun, 10 Feb 2008 12:45:38 GMT]]></title><description><![CDATA[<p>bei mir geht das wunderbar mit srand()</p>
<pre><code class="language-cpp">#include &lt;fstream.h&gt;
#include &lt;time.h&gt;

int main()
{
   int lottozahlen[7], i;

   srand(time(NULL));
   do
   {
      for (i = 0; i &lt; 7; i++)
         lottozahlen[i] = (rand() % 49) + 1;
   }
   while (doppelte(lottozahlen, 7) == 1);

   cout &lt;&lt; &quot;Lottozahlen:\n&quot;;
   for (i = 0; i &lt; 6; i++)
      cout &lt;&lt; lottozahlen[i] &lt;&lt; &quot; &quot;;
   cout &lt;&lt; endl;
   system (&quot;pause&quot;);
   return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1452972</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1452972</guid><dc:creator><![CDATA[kreater]]></dc:creator><pubDate>Sun, 10 Feb 2008 12:45:38 GMT</pubDate></item></channel></rss>