<?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[rand() nicht shuffle genug]]></title><description><![CDATA[<p>mahlzeit</p>
<p>folgendes</p>
<p>ich uebergeb der funktion rand() die zeit mit srand<br />
denk das ist die typische herangehensweise</p>
<p>nur wenn rand eine random zahl zwischen 1 und 10 bringen soll, dauert es schon sehr lange bis mal ne andere zahl rauskommt</p>
<p>es geht darum das es ein kleines programm ist was immer wieder neu gestartet wird<br />
und dadurch faengt immer gleich an irgendwie</p>
<p>kann man rand noch mehr shuffeln ?</p>
<pre><code class="language-cpp">m_minFiles = 1;
m_maxFiles = 10;

int number = RandomNumber( m_minFiles, m_maxFiles );
</code></pre>
<pre><code class="language-cpp">int WALL::RandomNumber(int min, int max)
{
	double number = ( ( (double) rand() / (double) RAND_MAX ) * max + min );
	return ( (int)number +1 );
}
</code></pre>
<p>die berechnung mit min/max hab ich mir aus der MSDN abgeschaut - &quot;frueher&quot; hatte ich immer mot modulo gearbeitet, wird aber das selbe ergeben</p>
<p>rand wird bei jeden programmlauf nur einmal aufgerufen direkt am start</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/150899/rand-nicht-shuffle-genug</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Jul 2026 00:06:06 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/150899.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 21 Jun 2006 10:21:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to rand() nicht shuffle genug on Wed, 21 Jun 2006 10:21:52 GMT]]></title><description><![CDATA[<p>mahlzeit</p>
<p>folgendes</p>
<p>ich uebergeb der funktion rand() die zeit mit srand<br />
denk das ist die typische herangehensweise</p>
<p>nur wenn rand eine random zahl zwischen 1 und 10 bringen soll, dauert es schon sehr lange bis mal ne andere zahl rauskommt</p>
<p>es geht darum das es ein kleines programm ist was immer wieder neu gestartet wird<br />
und dadurch faengt immer gleich an irgendwie</p>
<p>kann man rand noch mehr shuffeln ?</p>
<pre><code class="language-cpp">m_minFiles = 1;
m_maxFiles = 10;

int number = RandomNumber( m_minFiles, m_maxFiles );
</code></pre>
<pre><code class="language-cpp">int WALL::RandomNumber(int min, int max)
{
	double number = ( ( (double) rand() / (double) RAND_MAX ) * max + min );
	return ( (int)number +1 );
}
</code></pre>
<p>die berechnung mit min/max hab ich mir aus der MSDN abgeschaut - &quot;frueher&quot; hatte ich immer mot modulo gearbeitet, wird aber das selbe ergeben</p>
<p>rand wird bei jeden programmlauf nur einmal aufgerufen direkt am start</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1081955</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081955</guid><dc:creator><![CDATA[EXDW]]></dc:creator><pubDate>Wed, 21 Jun 2006 10:21:52 GMT</pubDate></item><item><title><![CDATA[Reply to rand() nicht shuffle genug on Wed, 21 Jun 2006 10:26:02 GMT]]></title><description><![CDATA[<p>Mr Evil schrieb:</p>
<blockquote>
<p>ich uebergeb der funktion rand() die zeit mit srand</p>
</blockquote>
<p>Dieser wirre Satz sieht im Code wie aus? Ich vermute da Unfug.</p>
<p>Deine Formel ist auch Mumpitz. Klappt so nur, wenn min 1 ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1081962</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081962</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Wed, 21 Jun 2006 10:26:02 GMT</pubDate></item><item><title><![CDATA[Reply to rand() nicht shuffle genug on Wed, 21 Jun 2006 10:30:45 GMT]]></title><description><![CDATA[<p>hab das nu so, weiss aber ne ob das nicht ein zu teures programm ist</p>
<pre><code class="language-cpp">int WALL::RandomNumber(int min, int max)
{
	double count = ( ( (double) rand() / (double) RAND_MAX ) * 10 + 1 );
	double number;
	for( int x=0; x&lt;=(int) count; x++ )
		number = ( ( (double) rand() / (double) RAND_MAX ) * max + min );

	return ( (int)number +1 );
}
</code></pre>
<p>'dazuedit</p>
<pre><code class="language-cpp">srand( (unsigned)time( NULL ) );
</code></pre>
<p>so natuerlich, die formel hab ich direkt aus der MSDN kopiert, und min ist bei mir immer 1</p>
<p>'nochmal dazuedit</p>
<p>ok, das geht natuerlich auch, ist auch sinnvoller, so wirds mehr shuffle</p>
<pre><code class="language-cpp">int WALL::RandomNumber(int min, int max)
{
	double number;
	for( int x=0; x&lt;=3 ; x++ )
		number = ( ( (double) rand() / (double) RAND_MAX ) * max + min );

	return ( (int)number +1 );
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1081963</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081963</guid><dc:creator><![CDATA[EXDW]]></dc:creator><pubDate>Wed, 21 Jun 2006 10:30:45 GMT</pubDate></item><item><title><![CDATA[Reply to rand() nicht shuffle genug on Wed, 21 Jun 2006 10:31:13 GMT]]></title><description><![CDATA[<p>Mr Evil schrieb:</p>
<blockquote>
<pre><code class="language-cpp">srand( (unsigned)time( NULL ) );
</code></pre>
</blockquote>
<p>Und wie (vor allem: wie oft) wird das ausgeführt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1081966</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081966</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Wed, 21 Jun 2006 10:31:13 GMT</pubDate></item><item><title><![CDATA[Reply to rand() nicht shuffle genug on Wed, 21 Jun 2006 10:51:22 GMT]]></title><description><![CDATA[<p>einmal direkt am start<br />
genau wie rand<br />
da es ein kleines programm ist, welches man oefter startet ist es notwendig das gleich das erste ergebnis je anders ist</p>
<p>'dazuedit</p>
<p>wie ich schon sagte<br />
es ist ein kleines programm<br />
das wird einmal gestartet - holt ne shuffle zahl und beendet schon wieder<br />
je nachdem wie man moechte ruft man das programm auf und nimmt sich ne neue zahl</p>
<p>das kann manchmal nichtmal ne sekunde danach sein wo es zuerst bereits beendet ist, manchmal ne minute dazwischen und manchmal mehr</p>
<p>je nachdem<br />
wenn ich das programm das erste mal aufruf, bekomm ich zb ne 6<br />
dann ruf ich es gleich nochmal auf und bekomm wieder ne 6<br />
10min spaeter dann bekomm ich erst ne andere zahl</p>
<p>da halt die systemzeit an rand uebergeben wird, denk cih liegt es daran</p>
<p>hab das nu so geloest das ich rand absichtlich oft aufruf, damit bei den einen start die zahl immer anders ist - schon klappts</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1081975</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081975</guid><dc:creator><![CDATA[EXDW]]></dc:creator><pubDate>Wed, 21 Jun 2006 10:51:22 GMT</pubDate></item><item><title><![CDATA[Reply to rand() nicht shuffle genug on Wed, 21 Jun 2006 23:38:59 GMT]]></title><description><![CDATA[<p>Ich hab' da mal an eine etwas abwegigere Möglichkeit gedacht:</p>
<pre><code class="language-cpp">#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;time.h&gt;

int get_random_number( ) {
	srand( (unsigned int )( time( 0 ) ) + rand( ) );
	return rand( );
}

int main( )
{
	for( int i = 0; i &lt; 100; ++i ) // simuliert deine Aufrufe schnell nacheinander
		printf( &quot;%i, &quot;, get_random_number( ) );

	printf( &quot;%i\n&quot;, get_random_number( ) );
}
</code></pre>
<p>Greetz, Swordfish</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1082589</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082589</guid><dc:creator><![CDATA[Swordfish]]></dc:creator><pubDate>Wed, 21 Jun 2006 23:38:59 GMT</pubDate></item></channel></rss>