<?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[random (10) begrenzen]]></title><description><![CDATA[<p>Hallo leute ich habe mal eine Frage.<br />
ich möchte gerne in eine forschleife zufall erzeugen, das nicht<br />
zweimal vorkommt.<br />
hat einer eine idee?</p>
<p>//--Diese Variante klappt leider rnicht</p>
<pre><code class="language-cpp">void __fastcall TForm1::Button1Click(TObject *Sender)
{
  randomize();
  for (int x = 0; x&lt;7;x++)
  {
  Zufall = random(7)+0;
  if (Zufall==Zufall)
     {
     Zufall= random(7)+0;
     }
  ListBox1-&gt;AddItem(IntToStr (Zufall),0) ;
  }
}
</code></pre>
<p>Dank im vorraus!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/143728/random-10-begrenzen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 05 Aug 2026 02:13:33 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/143728.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 11 Apr 2006 10:15:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to random (10) begrenzen on Tue, 11 Apr 2006 12:17:24 GMT]]></title><description><![CDATA[<p>Hallo leute ich habe mal eine Frage.<br />
ich möchte gerne in eine forschleife zufall erzeugen, das nicht<br />
zweimal vorkommt.<br />
hat einer eine idee?</p>
<p>//--Diese Variante klappt leider rnicht</p>
<pre><code class="language-cpp">void __fastcall TForm1::Button1Click(TObject *Sender)
{
  randomize();
  for (int x = 0; x&lt;7;x++)
  {
  Zufall = random(7)+0;
  if (Zufall==Zufall)
     {
     Zufall= random(7)+0;
     }
  ListBox1-&gt;AddItem(IntToStr (Zufall),0) ;
  }
}
</code></pre>
<p>Dank im vorraus!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1035052</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1035052</guid><dc:creator><![CDATA[amatuer]]></dc:creator><pubDate>Tue, 11 Apr 2006 12:17:24 GMT</pubDate></item><item><title><![CDATA[Reply to random (10) begrenzen on Tue, 11 Apr 2006 10:20:31 GMT]]></title><description><![CDATA[<p>Du mußt dir alle bisherigen Zahlen merken und vergleichen. (etwas ausführlicher wird's <a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-137211-and-highlight-is-zufall%2A.html" rel="nofollow">hier</a>)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1035053</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1035053</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Tue, 11 Apr 2006 10:20:31 GMT</pubDate></item><item><title><![CDATA[Reply to random (10) begrenzen on Tue, 11 Apr 2006 12:17:58 GMT]]></title><description><![CDATA[<p>Danke für den Tip CStoll <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="👍"
    /><br />
ja eine zweite forschleife in die erste schleife einbauen!<br />
das habe ich nun ausprobiert leider nach einigen test durchläufen,<br />
habe ich in der liste immer noch manchmal zwei gleiche Zahlen.</p>
<pre><code class="language-cpp">int Check[7];
  int Zufall;

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  randomize();
  for (int x = 0; x&lt;7;x++)
      {

       Zufall = random(7)+0;
       Check[x] =Zufall;
       for(int y= 0 ;y!=x;y++)
          {

          if (Check[y]==Zufall)
             {
              Zufall = random(7)+0;
             }
          }

   ListBox1-&gt;AddItem(IntToStr (Zufall),0) ;
  }
}
</code></pre>
<p>Vieleicht eine Idee warum Diese Variante nicht funktioniert?<br />
Dank im vorraus!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1035098</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1035098</guid><dc:creator><![CDATA[amatuer]]></dc:creator><pubDate>Tue, 11 Apr 2006 12:17:58 GMT</pubDate></item><item><title><![CDATA[Reply to random (10) begrenzen on Tue, 11 Apr 2006 11:33:51 GMT]]></title><description><![CDATA[<p>Du solltest die neue Zahl erst in dein Array eintragen, wenn du die Überprüfung durch hast.</p>
<p>(PS: Und um sieben verschiedene Zahlen zwischen 0 und 6 zu bestimmen, bietet sich vermutlich random_shuffle() an)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1035105</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1035105</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Tue, 11 Apr 2006 11:33:51 GMT</pubDate></item><item><title><![CDATA[Reply to random (10) begrenzen on Tue, 11 Apr 2006 12:20:23 GMT]]></title><description><![CDATA[<p>ich weis, ist nicht sonderlich schön, aber damit sollte es funktioniern:</p>
<pre><code class="language-cpp">void __fastcall TForm1::Button1Click(TObject *Sender)
{
  randomize();
  for (int x = 0; x&lt;7;x++)
  {

    Zufall = random(7)+0;
    Check[x] =Zufall;
    for(int y= 0 ;y!=x;y++)
    {

      if (Check[y]==Zufall)
      {
        x--;
      }
      else
      {
        ListBox1-&gt;AddItem(IntToStr (Zufall),0) ;
      }
    }

  }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1035108</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1035108</guid><dc:creator><![CDATA[666]]></dc:creator><pubDate>Tue, 11 Apr 2006 12:20:23 GMT</pubDate></item><item><title><![CDATA[Reply to random (10) begrenzen on Tue, 11 Apr 2006 12:21:06 GMT]]></title><description><![CDATA[<p>Bitte die <a href="http://www.c-plusplus.net/forum/faq.php?mode=bbcode" rel="nofollow">Code-Tags</a> verwenden. Danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1035166</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1035166</guid><dc:creator><![CDATA[Jansen]]></dc:creator><pubDate>Tue, 11 Apr 2006 12:21:06 GMT</pubDate></item><item><title><![CDATA[Reply to random (10) begrenzen on Tue, 11 Apr 2006 22:57:14 GMT]]></title><description><![CDATA[<p>Wie wärs mit einem Vektor?</p>
<pre><code class="language-cpp">std::set&lt;int&gt;zahl;
  randomize();
  while (zahl.size() &lt; 15)
  {
   zahl.insert(rand()%80 + 1);
  }

  std::vector&lt;int&gt;zahl_vector(zahl.begin(), zahl.end()); //Umwandeln nach Vektor

  //------------------------------------------- String basteln und Ausgeben

  for (i = 0; i &lt;= 14; i++)
 {
  randomset[i] = zahl_vector[i];
  v = v + &quot;   &quot; + IntToStr(zahl_vector[i]);
  Form7-&gt;Label2-&gt;Caption = v;

 }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1035583</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1035583</guid><dc:creator><![CDATA[Zero01]]></dc:creator><pubDate>Tue, 11 Apr 2006 22:57:14 GMT</pubDate></item><item><title><![CDATA[Reply to random (10) begrenzen on Tue, 11 Apr 2006 23:41:41 GMT]]></title><description><![CDATA[<p>ich denke da eher an sowas wie</p>
<pre><code class="language-cpp">void __fastcall TForm1::Button1Click(TObject *Sender)
{
  int Check[7]={0};//die anderen 6 nullen macht der compiler selber rein
  randomize();//besser nur einmal irgendwo in er main() oder so
  for (int x = 0; x&lt;7;x++)//siebenmal machen
  {
     int Zufall;
     do
       Zufall = random(7)+0;//würfeln
     while(!Check[Zufall]);//solange wiederholen, bis noch nicht genommene zahl
     Check[Zufall]=1;//zahl als genommen markieren
     ListBox1-&gt;AddItem(IntToStr (Zufall),0);//und ab in die anzeige
  }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1035590</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1035590</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Tue, 11 Apr 2006 23:41:41 GMT</pubDate></item><item><title><![CDATA[Reply to random (10) begrenzen on Wed, 12 Apr 2006 06:49:38 GMT]]></title><description><![CDATA[<p>Nur mal eine Frage aus Neugierde - was soll eigentlich das &quot;+0&quot; bei der Zufallsberechnung bewirken?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1035634</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1035634</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 12 Apr 2006 06:49:38 GMT</pubDate></item><item><title><![CDATA[Reply to random (10) begrenzen on Wed, 12 Apr 2006 09:25:59 GMT]]></title><description><![CDATA[<p>CStoll schrieb:</p>
<blockquote>
<p>Nur mal eine Frage aus Neugierde - was soll eigentlich das &quot;+0&quot; bei der Zufallsberechnung bewirken?</p>
</blockquote>
<p>ich schätze, es erlaubt, die wertemenge schneller zu erfassen, wenn man es immer verwendet.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1035755</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1035755</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Wed, 12 Apr 2006 09:25:59 GMT</pubDate></item><item><title><![CDATA[Reply to random (10) begrenzen on Wed, 12 Apr 2006 19:23:25 GMT]]></title><description><![CDATA[<p>Hallo alle ,<br />
ich möchte mich 1. von allen für die tollen Kommentare bedanken!!<br />
ich habe auch das beispiel von volkard ausprobiert. leider stuerz mein programm beim compoiliern immer wieder ab. vieleicht seht ihr hier ja ein fehler,was ich übersehen habe.<br />
dank im voraus!!!</p>
<pre><code>int Check[7]={0};//die anderen 6 nullen macht der compiler selber rein
  int Zufall;
 //---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  for (int x = 0; x&lt;7;x++)//siebenmal machen
  {

     do
       {
       Zufall = random(7)+0;//würfeln
       }
     while(!Check[Zufall]);//solange wiederholen, bis noch nicht genommene zahl
     {
     Check[Zufall]=1;//zahl als genommen markieren
     ListBox1-&gt;AddItem(IntToStr(Zufall),0);
     }
  }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{

  randomize();//besser nur einmal irgendwo in er main() oder so

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1036272</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1036272</guid><dc:creator><![CDATA[amatuer]]></dc:creator><pubDate>Wed, 12 Apr 2006 19:23:25 GMT</pubDate></item><item><title><![CDATA[Reply to random (10) begrenzen on Wed, 12 Apr 2006 20:03:58 GMT]]></title><description><![CDATA[<p>amatuer schrieb:</p>
<blockquote>
<p>leider stuerz mein programm beim compoiliern immer wieder ab.</p>
</blockquote>
<p>beim compilieren?<br />
ich würde es verstehen, wenn die funktion nur einmal funktionieren würde und beim zweitenmal abstürzen würde.<br />
weil int Check[7]={0}; nämlich echt ein lokales array in der funktion sein sollte, damit es auch jedesmal vor dem verwenden aufs neue mit nullen gefüllt wird.</p>
<p>edit:<br />
uups,<br />
while(!Check[Zufall])<br />
ist falsch</p>
<p>while(Check[Zufall]==1)<br />
war gemeint.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1036306</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1036306</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Wed, 12 Apr 2006 20:03:58 GMT</pubDate></item><item><title><![CDATA[Reply to random (10) begrenzen on Wed, 12 Apr 2006 21:35:42 GMT]]></title><description><![CDATA[<p>Wenn er sowieso immer alle Zahlen braucht währe sowas ratsamer:</p>
<pre><code class="language-cpp">int zahlen[7]={0,1,2,3,4,5,6};
randomize();
random_shuffle(zahlen,zahlen+7);
for(int i=0;i&lt;7;i++) ListBox1-&gt;Items-&gt;Add(zahlen[i]);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1036363</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1036363</guid><dc:creator><![CDATA[shuffler]]></dc:creator><pubDate>Wed, 12 Apr 2006 21:35:42 GMT</pubDate></item><item><title><![CDATA[Reply to random (10) begrenzen on Wed, 12 Apr 2006 22:11:36 GMT]]></title><description><![CDATA[<p>shuffler schrieb:</p>
<blockquote>
<p>Wenn er sowieso immer alle Zahlen braucht währe sowas ratsamer:</p>
<pre><code class="language-cpp">int zahlen[7]={0,1,2,3,4,5,6};
randomize();
random_shuffle(zahlen,zahlen+7);
for(int i=0;i&lt;7;i++) ListBox1-&gt;Items-&gt;Add(zahlen[i]);
</code></pre>
</blockquote>
<p>ja, kann schon sein. wie gehabt randomize() besser raus in die TForm1::FormCreate().<br />
ich wollte keine magische funktion vorstellen, die irgendwas irgendwie macht, sondern eine, die er komplett kapiert und die er dann auch beliebig anpassen kann.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1036378</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1036378</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Wed, 12 Apr 2006 22:11:36 GMT</pubDate></item></channel></rss>