<?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[ZufalsZahlen]]></title><description><![CDATA[<p>Hi, ich brauche zufalls Zahlen im Berreich von 1-1.000.000 und es dürfen keine doppelten Zahlen vorkommen.</p>
<p>Nun kann rand() ja irgend wie nur 32k verschiedene Zahlen zurückgeben.<br />
Wenn ich vor jedem rand() ein srand((unsigned int) time(NULL)); mache dauert das anlegen von 100 Zufallswerten schon ewig ... von 1.000.000 mal ganz abgesehen.</p>
<p>Hat zufällig jemand eine Idee wie ich das realisieren könnte ?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/182743/zufalszahlen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 00:29:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/182743.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 28 May 2007 18:04:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to ZufalsZahlen on Mon, 28 May 2007 18:04:00 GMT]]></title><description><![CDATA[<p>Hi, ich brauche zufalls Zahlen im Berreich von 1-1.000.000 und es dürfen keine doppelten Zahlen vorkommen.</p>
<p>Nun kann rand() ja irgend wie nur 32k verschiedene Zahlen zurückgeben.<br />
Wenn ich vor jedem rand() ein srand((unsigned int) time(NULL)); mache dauert das anlegen von 100 Zufallswerten schon ewig ... von 1.000.000 mal ganz abgesehen.</p>
<p>Hat zufällig jemand eine Idee wie ich das realisieren könnte ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1293973</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1293973</guid><dc:creator><![CDATA[Deltaone]]></dc:creator><pubDate>Mon, 28 May 2007 18:04:00 GMT</pubDate></item><item><title><![CDATA[Reply to ZufalsZahlen on Mon, 28 May 2007 18:10:26 GMT]]></title><description><![CDATA[<p>Vielleicht hilft dir Marcus`Artikel:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-172876-and-start-is-0.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-172876-and-start-is-0.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1293977</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1293977</guid><dc:creator><![CDATA[Kuldren]]></dc:creator><pubDate>Mon, 28 May 2007 18:10:26 GMT</pubDate></item><item><title><![CDATA[Reply to ZufalsZahlen on Mon, 28 May 2007 19:38:27 GMT]]></title><description><![CDATA[<p>Ja war ganz hilfreich.</p>
<p>Aber obwohl mein Programm nun eigentlich genügend zufallszahlen herstellen kann dauert es am 100.000 zufalls zahlen mega lange.</p>
<p>ggf. liegt es an der Art wie ich die abfrage mache ob eine Zahl schon mal vorgekommen ist:</p>
<pre><code class="language-cpp">a.clear(); // Inhalt löschen

	for(int i=0; i &lt;= n;)
	{	//
		// Zufahls Zahl erzeugen
		int rnd1 = rand();
		int rnd2 = rand();
		int rnd3 = rand();
		unsigned int zahl = ((rnd1 &amp; 0x03) &lt;&lt; 30) + (rnd2 &lt;&lt; 15) + rnd3;

		vector&lt;int&gt;::iterator k;
		bool kommtvor = false;
		for (k=a.begin();k!=a.end();k++)
		{
			if(*k == zahl)
			     kommtvor = true;
		}
		if(!kommtvor)
		{
			a.push_back(zahl);
			i++;
		}
	}
</code></pre>
<p>a ist ein Vector&lt;int&gt; und dient dazu zu gucken ob die Zahl schon einmal vorkam so das ich nacher in a zufällige Zahlen habe welche sich nicht wiederholen.<br />
Kann natürlich auch sein das mein PC zu lagsam ist oder aber das nicht genug Spiecher für das Projekt freigemacht wird ( laut Taskmanager 890k was doch etwas wenig erscheint)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1294021</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1294021</guid><dc:creator><![CDATA[Deltaone]]></dc:creator><pubDate>Mon, 28 May 2007 19:38:27 GMT</pubDate></item><item><title><![CDATA[Reply to ZufalsZahlen on Mon, 28 May 2007 20:09:54 GMT]]></title><description><![CDATA[<p>hm wenn die Zahlen nur je einmal vorkommen sollen nimm doch ein std::set bzw. das std::tr1::unordered_set, das sollte die Geschwindigkeit beim Nachschlagen deutlich erhöhen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1294043</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1294043</guid><dc:creator><![CDATA[darthdespotism]]></dc:creator><pubDate>Mon, 28 May 2007 20:09:54 GMT</pubDate></item><item><title><![CDATA[Reply to ZufalsZahlen on Mon, 28 May 2007 21:56:04 GMT]]></title><description><![CDATA[<p>hi,<br />
falls du 1 Mio. Zufallszahlen im direkten Zugriff, z.B. in einem Array halten willst und keine doppelt vorkommen darf, würde ich folgendes machen:<br />
Array 0..10^6-1 anlegen und in forschleife mit 0 bis 10^6-1 füllen. STL random- shuffle-funktion auf das array anwenden --&gt; mischt den Inhalt des arrays gleichverteilt auf.</p>
<p>Sehr guter Randomgenerator ist auch der Mersenne Twister von Makoto Matsumoto. Den hat mir mal jemand hier vom Forum empfohlen, und seither nehm ich den (alle anderen kannst du vergessen, auch was die Geschwindigkeit betrifft).</p>
<p>vg. tesu</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1294097</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1294097</guid><dc:creator><![CDATA[tesuji]]></dc:creator><pubDate>Mon, 28 May 2007 21:56:04 GMT</pubDate></item></channel></rss>