<?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 zwischen 1 und ? !]]></title><description><![CDATA[<p>wie kann ich eine zufallszahl zwischen 1 und ? finden lassen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/233140/zufallszahl-zwischen-1-und</link><generator>RSS for Node</generator><lastBuildDate>Fri, 25 Sep 2026 02:17:19 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/233140.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 01 Feb 2009 11:17:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to zufallszahl zwischen 1 und ? ! on Sun, 01 Feb 2009 11:17:04 GMT]]></title><description><![CDATA[<p>wie kann ich eine zufallszahl zwischen 1 und ? finden lassen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1655842</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655842</guid><dc:creator><![CDATA[Blake_MaX]]></dc:creator><pubDate>Sun, 01 Feb 2009 11:17:04 GMT</pubDate></item><item><title><![CDATA[Reply to zufallszahl zwischen 1 und ? ! on Sun, 01 Feb 2009 11:18:46 GMT]]></title><description><![CDATA[<p><a href="http://www.cplusplus.com/reference/clibrary/cstdlib/rand.html" rel="nofollow">http://www.cplusplus.com/reference/clibrary/cstdlib/rand.html</a></p>
<p>Wenn du bei google mal eingegeben hättest &quot;C++ zufallszahl&quot; hättest du das von alleine gefunden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1655843</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655843</guid><dc:creator><![CDATA[Firefighter]]></dc:creator><pubDate>Sun, 01 Feb 2009 11:18:46 GMT</pubDate></item><item><title><![CDATA[Reply to zufallszahl zwischen 1 und ? ! on Sun, 01 Feb 2009 11:25:38 GMT]]></title><description><![CDATA[<p>ok danke...war dumm</p>
<p>mfg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1655849</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655849</guid><dc:creator><![CDATA[Blake_MaX]]></dc:creator><pubDate>Sun, 01 Feb 2009 11:25:38 GMT</pubDate></item><item><title><![CDATA[Reply to zufallszahl zwischen 1 und ? ! on Sun, 01 Feb 2009 11:39:28 GMT]]></title><description><![CDATA[<p>ok, und wie bekomme ich das jetz hin, das er mir 5mal eine rand() zahl bestimmt? ohne das ich gleich 5 int mit rand() deklarieren muss?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1655859</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655859</guid><dc:creator><![CDATA[Blake_MaX]]></dc:creator><pubDate>Sun, 01 Feb 2009 11:39:28 GMT</pubDate></item><item><title><![CDATA[Reply to zufallszahl zwischen 1 und ? ! on Sun, 01 Feb 2009 11:49:26 GMT]]></title><description><![CDATA[<p>Blake_MaX schrieb:</p>
<blockquote>
<p>ok, und wie bekomme ich das jetz hin, das er mir 5mal eine rand() zahl bestimmt? ohne das ich gleich 5 int mit rand() deklarieren muss?</p>
</blockquote>
<p>Schon einmal etwas von Arrays/Container und Schleifen gehört?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1655868</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655868</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Sun, 01 Feb 2009 11:49:26 GMT</pubDate></item><item><title><![CDATA[Reply to zufallszahl zwischen 1 und ? ! on Sun, 01 Feb 2009 11:51:29 GMT]]></title><description><![CDATA[<p>ja hab ich wenn ich das in ne while schleife lege, gibt er mir immer wieder die gleiche rand zahl aus! ich will aber verschiedene!</p>
<p>mfg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1655869</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655869</guid><dc:creator><![CDATA[Blake_MaX]]></dc:creator><pubDate>Sun, 01 Feb 2009 11:51:29 GMT</pubDate></item><item><title><![CDATA[Reply to zufallszahl zwischen 1 und ? ! on Sun, 01 Feb 2009 11:54:27 GMT]]></title><description><![CDATA[<p>Blake_MaX schrieb:</p>
<blockquote>
<p>ja hab ich wenn ich das in ne while schleife lege, gibt er mir immer wieder die gleiche rand zahl aus! ich will aber verschiedene!</p>
<p>mfg</p>
</blockquote>
<pre><code class="language-cpp">::srand ( static_cast&lt;unsigned int&gt; ( ::timeGetTime () ) );
</code></pre>
<p>In die main packen und nur einmal aufrufen!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1655871</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655871</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Sun, 01 Feb 2009 11:54:27 GMT</pubDate></item><item><title><![CDATA[Reply to zufallszahl zwischen 1 und ? ! on Sun, 01 Feb 2009 11:55:05 GMT]]></title><description><![CDATA[<p>Blake_MaX schrieb:</p>
<blockquote>
<p>ja hab ich wenn ich das in ne while schleife lege, gibt er mir immer wieder die gleiche rand zahl aus! ich will aber verschiedene!</p>
</blockquote>
<p>du rufst sicher jedesmal srand() auf, richtig?<br />
lies dir dazu die beschreibung von srand durch</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1655872</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655872</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Sun, 01 Feb 2009 11:55:05 GMT</pubDate></item><item><title><![CDATA[Reply to zufallszahl zwischen 1 und ? ! on Sun, 01 Feb 2009 12:00:46 GMT]]></title><description><![CDATA[<p>drakon schrieb:</p>
<blockquote>
<pre><code class="language-cpp">::srand ( static_cast&lt;unsigned int&gt; ( ::timeGetTime () ) );
</code></pre>
</blockquote>
<p>wozu der static_cast? der sollte doch auf gefahr hinweisen. ich seh hier aber keine. gar keine.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1655876</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655876</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 01 Feb 2009 12:00:46 GMT</pubDate></item><item><title><![CDATA[Reply to zufallszahl zwischen 1 und ? ! on Sun, 01 Feb 2009 12:04:11 GMT]]></title><description><![CDATA[<p>bringt nichts! mein code sieht folgendermaßen aus:</p>
<p>while(userrandcount &lt; 6) {<br />
userrand = rand() % 8 + 1;<br />
srand ( static_cast&lt;unsigned int&gt; ( 1 ) );<br />
switch(userrand) {<br />
case 1: cout&lt;&lt;a1&lt;&lt;&quot;a1&quot;&lt;&lt;endl; userrandcount++; break;<br />
case 2: cout&lt;&lt;a2&lt;&lt;&quot;a2&quot;&lt;&lt;endl; userrandcount++; break;<br />
case 3: cout&lt;&lt;a3&lt;&lt;&quot;a2&quot;&lt;&lt;endl; userrandcount++; break;<br />
case 4: cout&lt;&lt;a4&lt;&lt;&quot;a2&quot;&lt;&lt;endl; userrandcount++; break;<br />
case 5: cout&lt;&lt;b1&lt;&lt;&quot;a2&quot;&lt;&lt;endl; userrandcount++; break;<br />
case 6: cout&lt;&lt;b2&lt;&lt;&quot;a2&quot;&lt;&lt;endl; userrandcount++; break;<br />
case 7: cout&lt;&lt;b3&lt;&lt;&quot;a2&quot;&lt;&lt;endl; userrandcount++; break;<br />
case 8: cout&lt;&lt;b4&lt;&lt;&quot;a2&quot;&lt;&lt;endl; userrandcount++; break;<br />
}<br />
}<br />
hab auch schon nur in der main gehabt bringt aber auch nichts! hab auch schon anstelle der 1 ne 0 eingefügt so wie auf <a href="http://www.cplusplus.com/reference/clibrary/cstdlib/srand.html" rel="nofollow">http://www.cplusplus.com/reference/clibrary/cstdlib/srand.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1655880</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655880</guid><dc:creator><![CDATA[Blake_MaX]]></dc:creator><pubDate>Sun, 01 Feb 2009 12:04:11 GMT</pubDate></item><item><title><![CDATA[Reply to zufallszahl zwischen 1 und ? ! on Sun, 01 Feb 2009 12:07:09 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>drakon schrieb:</p>
<blockquote>
<pre><code class="language-cpp">::srand ( static_cast&lt;unsigned int&gt; ( ::timeGetTime () ) );
</code></pre>
</blockquote>
<p>wozu der static_cast? der sollte doch auf gefahr hinweisen. ich seh hier aber keine. gar keine.</p>
</blockquote>
<p>Ich mache den da einfach, weil timeGetTime ein DWORD (unsigned long) zurückgibt und srand ein unsigned int nimmt. Reine Gewohnheit, weil die Typen nicht übereinstimmen. Man kann es natürlich auch ohne cast machen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1655881</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655881</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Sun, 01 Feb 2009 12:07:09 GMT</pubDate></item><item><title><![CDATA[Reply to zufallszahl zwischen 1 und ? ! on Sun, 01 Feb 2009 12:08:41 GMT]]></title><description><![CDATA[<p>Blake_MaX schrieb:</p>
<blockquote>
<p>bringt nichts! mein code sieht folgendermaßen aus:</p>
<p>...</p>
</blockquote>
<p>Du rufst da srand aber in einer Schleife auf. Die sollst du in der main genau <strong>ein einziges</strong> mal aufrufen!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1655884</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655884</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Sun, 01 Feb 2009 12:08:41 GMT</pubDate></item><item><title><![CDATA[Reply to zufallszahl zwischen 1 und ? ! on Sun, 01 Feb 2009 12:10:45 GMT]]></title><description><![CDATA[<p>Blake_MaX schrieb:</p>
<blockquote>
<p>bringt nichts!</p>
</blockquote>
<p>klar.<br />
srand ( static_cast&lt;unsigned int&gt; ( 1 ) );<br />
tut nicht gut sein.</p>
<pre><code class="language-cpp">srand (time(0)); //nach #include &lt;ctime&gt;
</code></pre>
<p>oder drakons</p>
<pre><code class="language-cpp">::srand ( static_cast&lt;unsigned int&gt; ( ::timeGetTime () ) ); //nach #include
</code></pre>
<p>&lt;windows.h&gt;<br />
und das srand NUR EINMAL AM BESTEN AM ANGANG DER MAIN aufrufen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1655885</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655885</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 01 Feb 2009 12:10:45 GMT</pubDate></item><item><title><![CDATA[Reply to zufallszahl zwischen 1 und ? ! on Sun, 01 Feb 2009 12:11:40 GMT]]></title><description><![CDATA[<p>wie gesagt das hatte ich schon vorher gemacht aber das war wohl irgendwie falsch danke für die hilfe!</p>
<p>und jetzt noch eine letzt frage, um zu bestimmen, dass er immer verschiedene zahlen ausgibt, gibt es da auch einen extra befehl, oder muss ich mit if und so deklarieren?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1655886</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655886</guid><dc:creator><![CDATA[Blake_MaX]]></dc:creator><pubDate>Sun, 01 Feb 2009 12:11:40 GMT</pubDate></item><item><title><![CDATA[Reply to zufallszahl zwischen 1 und ? ! on Sun, 01 Feb 2009 12:14:04 GMT]]></title><description><![CDATA[<p>die sind immer verschieden weil srand(uhrzeit()) den zufallszahlengenerator bei jedem programmstart mit der uhrzeit initialisiert. und du immer zu ner anderen uhrzeit startest.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1655889</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655889</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 01 Feb 2009 12:14:04 GMT</pubDate></item><item><title><![CDATA[Reply to zufallszahl zwischen 1 und ? ! on Sun, 01 Feb 2009 12:16:13 GMT]]></title><description><![CDATA[<p>h stimmt du hast recht! vielen dank!!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1655890</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655890</guid><dc:creator><![CDATA[Blake_MaX]]></dc:creator><pubDate>Sun, 01 Feb 2009 12:16:13 GMT</pubDate></item><item><title><![CDATA[Reply to zufallszahl zwischen 1 und ? ! on Sun, 01 Feb 2009 12:25:09 GMT]]></title><description><![CDATA[<p>Ich würde empfehlen für Debuging Vorgänge feste Werte zu nehmen, oder zumindest die Werte mitzuloggen, da du ansonsten den Fehler kaum noch nachvollziehen kannst, wenn du den Wert, den du übergibst nicht kennst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1655893</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1655893</guid><dc:creator><![CDATA[drakon]]></dc:creator><pubDate>Sun, 01 Feb 2009 12:25:09 GMT</pubDate></item><item><title><![CDATA[Reply to zufallszahl zwischen 1 und ? ! on Sun, 01 Feb 2009 22:32:00 GMT]]></title><description><![CDATA[<p>Du kannst auch innerhalb des Programmflusses <code>srand()</code> einsetzen, oder eben nicht - je nachdem, ob du die gleiche Zahlenfolge willst.</p>
<p>Und ansonsten reicht ein &quot;//&quot; vor dem Aufruf. Übrigens gibt es in C++ keine Befehle, sondern Anweisungen und Funktionen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1656235</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1656235</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sun, 01 Feb 2009 22:32:00 GMT</pubDate></item><item><title><![CDATA[Reply to zufallszahl zwischen 1 und ? ! on Sun, 01 Feb 2009 22:36:17 GMT]]></title><description><![CDATA[<p>Nexus schrieb:</p>
<blockquote>
<p>Übrigens gibt es in C++ keine Befehle, sondern Anweisungen und Funktionen.</p>
</blockquote>
<p>wobei aber funktionsaufrufe befehle sind.</p>
<p>die frage &quot;mit welcher funktion initialisiere ich den zufallszahlengenerator&quot; beantwortet man mit &quot;srand&quot;.<br />
die frage &quot;mit welchem befehl initialisiere ich den zufallszahlengenerator&quot; beantwortet man mit &quot;srand(time(0));&quot;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1656238</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1656238</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sun, 01 Feb 2009 22:36:17 GMT</pubDate></item><item><title><![CDATA[Reply to zufallszahl zwischen 1 und ? ! on Mon, 02 Feb 2009 00:07:30 GMT]]></title><description><![CDATA[<p>&quot;Befehle&quot; würde ich aber in C++ nicht verwenden, da das zu Missverständnissen führen kann. Meines Erachtens ist dieser Begriff eher in maschinennaher Programmierung (Assembler), bei der immer einzelne ALU-Befehle gemeint sind, gebräuchlich.</p>
<p>Dass es keine Befehle &quot;gibt&quot; - da hast du Recht - war wohl zu strikt formuliert (es gibt ja auch Inline-Assembler etc)...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1656271</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1656271</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Mon, 02 Feb 2009 00:07:30 GMT</pubDate></item></channel></rss>