<?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[Grosse Zufallszahlen mit rand()]]></title><description><![CDATA[<p>Hallo.</p>
<p>Habe das Problem, dass rand() mir Zufallszahlen bis max. 32768 generiert. Dafür sei die Konstante RAND_MAX zuständig.</p>
<p>Da rand() jedoch ein 'int' zurückgibt und 'int' bei c++/Intel CPUs 4 Byte gross ist, hätte ich eigentich gerne, dass rand() eine grössere Zahl zurückgibt.. wie kann man RAND_MAX neu definieren?</p>
<p>Meine Zufallszahl müsste 9 Stellen besitzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/123023/grosse-zufallszahlen-mit-rand</link><generator>RSS for Node</generator><lastBuildDate>Sun, 23 Aug 2026 13:05:24 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/123023.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 12 Oct 2005 10:52:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Grosse Zufallszahlen mit rand() on Wed, 12 Oct 2005 10:52:06 GMT]]></title><description><![CDATA[<p>Hallo.</p>
<p>Habe das Problem, dass rand() mir Zufallszahlen bis max. 32768 generiert. Dafür sei die Konstante RAND_MAX zuständig.</p>
<p>Da rand() jedoch ein 'int' zurückgibt und 'int' bei c++/Intel CPUs 4 Byte gross ist, hätte ich eigentich gerne, dass rand() eine grössere Zahl zurückgibt.. wie kann man RAND_MAX neu definieren?</p>
<p>Meine Zufallszahl müsste 9 Stellen besitzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/890453</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/890453</guid><dc:creator><![CDATA[sky21]]></dc:creator><pubDate>Wed, 12 Oct 2005 10:52:06 GMT</pubDate></item><item><title><![CDATA[Reply to Grosse Zufallszahlen mit rand() on Wed, 12 Oct 2005 11:04:12 GMT]]></title><description><![CDATA[<p>sky21 schrieb:</p>
<blockquote>
<p>Hallo.</p>
<p>Habe das Problem, dass rand() mir Zufallszahlen bis max. 32768 generiert. Dafür sei die Konstante RAND_MAX zuständig.</p>
<p>Da rand() jedoch ein 'int' zurückgibt und 'int' bei c++/Intel CPUs 4 Byte gross ist, hätte ich eigentich gerne, dass rand() eine grössere Zahl zurückgibt.. wie kann man RAND_MAX neu definieren?</p>
<p>Meine Zufallszahl müsste 9 Stellen besitzen.</p>
</blockquote>
<p>a) zusammenstückeln<br />
return rand()|(rand()&lt;&lt;10)|(rand()&lt;&lt;20);</p>
<p>b) nen bessern generator nehmen<br />
//seeds ungetestet</p>
<pre><code class="language-cpp">#ifndef RANDOM_HPP
#define RANDOM_HPP

#include &quot;types.hpp&quot;

//multiply-with-carry prng
//quelle
//http://cliodhna.cop.uop.edu/~hetrick/na_faq.html
//TODO: testen, ob alle seeds!=0 gute seeds sind

class Random{
private:
	u64 x;
public:
	Random(u64 seed){
		x=seed|(u64(1)&lt;&lt;32);
	}
	u32 operator()(){
		x=1967773755*(x&amp;0xffffffff)+(x&gt;&gt;32);
		return x;
	}
};

#endif
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/890467</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/890467</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Wed, 12 Oct 2005 11:04:12 GMT</pubDate></item><item><title><![CDATA[Reply to Grosse Zufallszahlen mit rand() on Wed, 12 Oct 2005 11:09:48 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>return rand()|(rand()&lt;&lt;10)|(rand()&lt;&lt;20);</p>
</blockquote>
<p>Das habe ich auch schon versucht, 3 Blücke à 3 Zeichen grosse Zahlen zu generieren und zusammenzusetzem.<br />
Das Problem ist hier jedoch, dass die Gesamtzahl dann noch Modulo &lt;2-Stellige Primzahl&gt; 0 ergeben muss.<br />
In der Praxis geht das eben leider verdammt lange, muss so ein Fall gefunden wird...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/890472</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/890472</guid><dc:creator><![CDATA[sky21]]></dc:creator><pubDate>Wed, 12 Oct 2005 11:09:48 GMT</pubDate></item><item><title><![CDATA[Reply to Grosse Zufallszahlen mit rand() on Wed, 12 Oct 2005 11:13:04 GMT]]></title><description><![CDATA[<p>sky21 schrieb:</p>
<blockquote>
<p>volkard schrieb:</p>
<blockquote>
<p>return rand()|(rand()&lt;&lt;10)|(rand()&lt;&lt;20);</p>
</blockquote>
<p>Das habe ich auch schon versucht, 3 Blücke à 3 Zeichen grosse Zahlen zu generieren und zusammenzusetzem.<br />
Das Problem ist hier jedoch, dass die Gesamtzahl dann noch Modulo &lt;2-Stellige Primzahl&gt; 0 ergeben muss.<br />
In der Praxis geht das eben leider verdammt lange, muss so ein Fall gefunden wird...</p>
</blockquote>
<p>berechne doch einfach den bigrand und dann b=int(b/97)*97;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/890475</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/890475</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Wed, 12 Oct 2005 11:13:04 GMT</pubDate></item><item><title><![CDATA[Reply to Grosse Zufallszahlen mit rand() on Thu, 13 Oct 2005 21:04:06 GMT]]></title><description><![CDATA[<p>sky21 schrieb:</p>
<blockquote>
<p>Das Problem ist hier jedoch, dass die Gesamtzahl dann noch Modulo &lt;2-Stellige Primzahl&gt; 0 ergeben muss.<br />
In der Praxis geht das eben leider verdammt lange, muss so ein Fall gefunden wird...</p>
</blockquote>
<p>So 'ne Zahl ist auch nicht zufällig.</p>
<p>Bye, TGGC (<a href="http://tggc.tg.funpic.de/index.php?cat=4" rel="nofollow">Demo or Die</a>)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/891838</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/891838</guid><dc:creator><![CDATA[TGGC]]></dc:creator><pubDate>Thu, 13 Oct 2005 21:04:06 GMT</pubDate></item></channel></rss>