<?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-funktionen in WinAPI ?!?]]></title><description><![CDATA[<p>Also ich habe mal eine Frage...<br />
und zwar ob es sein kann das es in der WinAPI keine random() befehle gibt...<br />
Denn ich habe ein programm in dem ich die nutzen möchte... Jedoch wird mir gesagt das die befehle srand() und rand() ungültige befehle sind und das std ein ungültiger namespace ist.</p>
<p>Liegt das an WinAPI oder mache ich da einen fehler....</p>
<p>Includen würde ich dafür die &lt;iostream&gt; und die &lt;time.h&gt;<br />
für iostream bräuchte ich using namespace std;<br />
doch da wird mir gesagt das es das nicht gibt...</p>
<p>Danke schon mal an alle die mir helfen wollen</p>
<p>MFG Sqwan</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/184406/random-funktionen-in-winapi</link><generator>RSS for Node</generator><lastBuildDate>Mon, 06 Jul 2026 06:12:33 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/184406.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 14 Jun 2007 21:09:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Random-funktionen in WinAPI ?!? on Thu, 14 Jun 2007 21:09:27 GMT]]></title><description><![CDATA[<p>Also ich habe mal eine Frage...<br />
und zwar ob es sein kann das es in der WinAPI keine random() befehle gibt...<br />
Denn ich habe ein programm in dem ich die nutzen möchte... Jedoch wird mir gesagt das die befehle srand() und rand() ungültige befehle sind und das std ein ungültiger namespace ist.</p>
<p>Liegt das an WinAPI oder mache ich da einen fehler....</p>
<p>Includen würde ich dafür die &lt;iostream&gt; und die &lt;time.h&gt;<br />
für iostream bräuchte ich using namespace std;<br />
doch da wird mir gesagt das es das nicht gibt...</p>
<p>Danke schon mal an alle die mir helfen wollen</p>
<p>MFG Sqwan</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1306091</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1306091</guid><dc:creator><![CDATA[Sqwan]]></dc:creator><pubDate>Thu, 14 Jun 2007 21:09:27 GMT</pubDate></item><item><title><![CDATA[Reply to Random-funktionen in WinAPI ?!? on Thu, 14 Jun 2007 21:11:49 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;cstdlib&gt;
</code></pre>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> .</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1306094</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1306094</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Thu, 14 Jun 2007 21:11:49 GMT</pubDate></item><item><title><![CDATA[Reply to Random-funktionen in WinAPI ?!? on Thu, 14 Jun 2007 21:14:33 GMT]]></title><description><![CDATA[<p>habe ich schon versucht</p>
<p>--------------------Konfiguration: test - Win32 Debug--------------------<br />
Kompilierung läuft...<br />
test.cpp<br />
K:\test\test.cpp(8) : error C2871: 'std' : Existiert nicht oder ist kein Namespace<br />
K:\test\test.cpp(113) : error C2065: 'srand' : nichtdeklarierter Bezeichner<br />
K:\test\test.cpp(114) : error C2065: 'rand' : nichtdeklarierter Bezeichner<br />
Fehler beim Ausführen von cl.exe.</p>
<p>test.exe - 3 Fehler, 0 Warnung(en)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1306099</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1306099</guid><dc:creator><![CDATA[Sqwan]]></dc:creator><pubDate>Thu, 14 Jun 2007 21:14:33 GMT</pubDate></item><item><title><![CDATA[Reply to Random-funktionen in WinAPI ?!? on Thu, 14 Jun 2007 21:18:38 GMT]]></title><description><![CDATA[<p>Die Funktionen liegen nicht im Namensbereich std.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1306105</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1306105</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Thu, 14 Jun 2007 21:18:38 GMT</pubDate></item><item><title><![CDATA[Reply to Random-funktionen in WinAPI ?!? on Thu, 14 Jun 2007 21:27:06 GMT]]></title><description><![CDATA[<p>Das habe ich auch schon wech gelassen...</p>
<p>--------------------Konfiguration: test - Win32 Debug--------------------<br />
Kompilierung läuft...<br />
test.cpp<br />
K:\test\test.cpp(111) : error C2065: 'srand' : nichtdeklarierter Bezeichner<br />
K:\test\test.cpp(112) : error C2065: 'rand' : nichtdeklarierter Bezeichner<br />
Fehler beim Ausführen von cl.exe.</p>
<p>test.exe - 2 Fehler, 0 Warnung(en)</p>
<p>Dann habe ich nurnoch das...<br />
Das verstehe ich einfach nicht...</p>
<p>hier mal meine ganzer Kopf...</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;time.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;cstdlib&gt;
#include &lt;iostream.h&gt;
#include &quot;stdafx.h&quot;

const UINT TimerID  = 1;
const UINT SizeX    = 800;
const UINT SizeY    = 600;
const char szAppName[] = &quot;Stop-Uhr&quot;;
static RECT     rect;
	   int  iMSec = 0;
	   int  iSec  = 0;
	   int  iMin  = 0;
	   int  iStd  = 0;
	   int  iTag  = 0;
	   bool isActive = false;
	   int  fx = 10;
	   int  fy = 50;
	   int x;
</code></pre>
<p>Ich benutze übrigens die Visual Studio 6.0 Autorenedition.<br />
Außerdem habe ich eine einfache Win32 anwendung erstellt...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1306113</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1306113</guid><dc:creator><![CDATA[Sqwan]]></dc:creator><pubDate>Thu, 14 Jun 2007 21:27:06 GMT</pubDate></item><item><title><![CDATA[Reply to Random-funktionen in WinAPI ?!? on Thu, 14 Jun 2007 21:29:13 GMT]]></title><description><![CDATA[<p>Hm...also bei mir reicht sowohl &lt;iostream&gt; (ohne '.h' (!) - das '.h' ist veraltet und sollte nicht mehr verwendet werden) als auch &lt;cstdlib&gt;.</p>
<p>Welchen/e Compiler/IDE verwendest Du denn ? ... MS Visual C++ 6.0 ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1306121</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1306121</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Thu, 14 Jun 2007 21:29:13 GMT</pubDate></item><item><title><![CDATA[Reply to Random-funktionen in WinAPI ?!? on Thu, 14 Jun 2007 21:37:40 GMT]]></title><description><![CDATA[<p>Jop MS 6.0</p>
<p>Deshalb verstehe ich es ja auch nicht... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":-("
      alt="😞"
    /> es geht einfach nicht...</p>
<p>ich habe 1000 bibliotheken versucht...</p>
<p>iostream.h und auch ohne...<br />
und iostream mit namespace std;<br />
Nichts ging</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1306132</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1306132</guid><dc:creator><![CDATA[Sqwan]]></dc:creator><pubDate>Thu, 14 Jun 2007 21:37:40 GMT</pubDate></item><item><title><![CDATA[Reply to Random-funktionen in WinAPI ?!? on Thu, 14 Jun 2007 21:42:26 GMT]]></title><description><![CDATA[<p>Hm sehr merkwürdig...also hab das:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

int main()
{
	rand();
	srand(0);

	return (0);
}
</code></pre>
<p>auch mal aufer MS VC++ 6.0 getestet und es funktioniert einwandfrei <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f4a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--light_bulb"
      title=":bulb:"
      alt="💡"
    /> . Vllt hast Du ein falschen Projekt erstellt, oder den Compiler falsch eingerichtet... . Kann ich aber so nicht nachvollziehen... evtl. lohnt sich auch das installieren der noch verfügbaren Service-Packs, falls es n interner Fehler ist...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1306135</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1306135</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Thu, 14 Jun 2007 21:42:26 GMT</pubDate></item><item><title><![CDATA[Reply to Random-funktionen in WinAPI ?!? on Thu, 14 Jun 2007 21:44:00 GMT]]></title><description><![CDATA[<p>--------------------Konfiguration: versuch - Win32 Debug--------------------<br />
Kompilierung läuft...<br />
versuch.cpp<br />
c:\dokumente und einstellungen\master\eigene dateien\neuer ordner\versuch\versuch.cpp(112) : error C2660: 'rand' : Funktion akzeptiert keine 1 Parameter<br />
Fehler beim Ausführen von cl.exe.</p>
<p>versuch.exe - 1 Fehler, 0 Warnung(en)</p>
<p>Soa ich bin schon mal weiter....</p>
<p>Ich habe die &quot;stdafx.h&quot; raus genommen und eingesttellt das vorkompilierte header-dateien nicht genutzt werden...</p>
<p>Jetzt kommt nurnoch das rand keine 1 parameter haben will..<br />
aber die klammern sind leer...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1306137</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1306137</guid><dc:creator><![CDATA[Sqwan]]></dc:creator><pubDate>Thu, 14 Jun 2007 21:44:00 GMT</pubDate></item><item><title><![CDATA[Reply to Random-funktionen in WinAPI ?!? on Thu, 14 Jun 2007 22:09:14 GMT]]></title><description><![CDATA[<p>Klar gibt es in der WinApi eine random-Funktion: &quot;CryptGenRandom&quot;.</p>
<p>Und die ist im Gegensatz zu den schon genannten Oldtimern auch kryptografisch sicher.</p>
<p><a href="http://msdn2.microsoft.com/en-us/library/aa379942.aspx" rel="nofollow">http://msdn2.microsoft.com/en-us/library/aa379942.aspx</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1306158</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1306158</guid><dc:creator><![CDATA[_mgs]]></dc:creator><pubDate>Thu, 14 Jun 2007 22:09:14 GMT</pubDate></item><item><title><![CDATA[Reply to Random-funktionen in WinAPI ?!? on Thu, 14 Jun 2007 22:53:30 GMT]]></title><description><![CDATA[<p>Sqwan schrieb:</p>
<blockquote>
<p>Jetzt kommt nurnoch das rand keine 1 parameter haben will..<br />
aber die klammern sind leer...</p>
</blockquote>
<p>Guck nochmal richtig, das sind sie sicher nicht.<br />
Sorry wenn das jetzt doof klingt, aber wenn sie wirklich leer sind, dann ist dein Compiler im Eimer.</p>
<p>Wolltest du vielleicht srand schreiben und hast das s weggelassen? Und dann drübergelesen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1306171</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1306171</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Thu, 14 Jun 2007 22:53:30 GMT</pubDate></item><item><title><![CDATA[Reply to Random-funktionen in WinAPI ?!? on Fri, 15 Jun 2007 11:10:18 GMT]]></title><description><![CDATA[<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":-D"
      alt="😃"
    /> Der fehler lag woanders...</p>
<p>Ich benutze die rand() funktion nicht nur einmal...</p>
<p>Und an einer anderen stelle habe ich rand(x) stehen gehabt...<br />
An der stelle hatte ich nicht geguckt weil ich vergessen hatte das ich die da auch habe...<br />
War halt schon spät <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":-D"
      alt="😃"
    /></p>
<p>Geht jetzt....</p>
<pre><code class="language-cpp">srand((unsigned long)time(NULL)+x1);
x1=(rand()%800);
</code></pre>
<p>schaut nun so aus..</p>
<p>Was mich nun aber interessiert ist dieses &quot;CryptGenRandom&quot;<br />
hat das schon mal wer verwendet?</p>
<p>Kann dazu vllt mal einer ein 3 zeilen bsp machen?<br />
Weil iwie verwirrt es mich das nur wahr oder falsch zurückgegeben werden kann...<br />
Aber ich brauche ja eine zahl :-S</p>
<p>Naja... Herzlichen dank für die hilfe...<br />
Habt mir schon sehr geholfen...</p>
<p>Sqwan</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1306441</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1306441</guid><dc:creator><![CDATA[Sqwan]]></dc:creator><pubDate>Fri, 15 Jun 2007 11:10:18 GMT</pubDate></item><item><title><![CDATA[Reply to Random-funktionen in WinAPI ?!? on Fri, 15 Jun 2007 13:37:10 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">//--------------------------------------------------------------------
// Declare and initialize variables.

HCRYPTPROV   hCryptProv;
BYTE         pbData[16];

//--------------------------------------------------------------------
//  This code assumes that a cryptographic context has been acquired 
//  For code details, see &quot;Example C Program: Duplicating a Session 
//  Key.&quot;

//--------------------------------------------------------------------
// Generate a random initialization vector.

if(CryptGenRandom(
   hCryptProv, 
   8, 
   pbData)) 
{
     printf(&quot;Random sequence generated. \n&quot;);
}
else
{
     printf(&quot;Error during CryptGenRandom.\n&quot;);
     exit(1);
}
</code></pre>
<p>Quelle msdn <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>die Funktion füllt den speicherbereich pbData mit random werten. Das hat den vorteil das du nichtmehr auf randmax beschränkt bist sondern wenn du willst auch eine 1MB große random zahl createn. ohne rand() mehrmals aufzurufen.</p>
<p>mfg tobZel</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1306598</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1306598</guid><dc:creator><![CDATA[tobZel]]></dc:creator><pubDate>Fri, 15 Jun 2007 13:37:10 GMT</pubDate></item><item><title><![CDATA[Reply to Random-funktionen in WinAPI ?!? on Fri, 15 Jun 2007 19:44:42 GMT]]></title><description><![CDATA[<p>Sqwan schrieb:</p>
<blockquote>
<p>Und an einer anderen stelle habe ich rand(x) stehen gehabt...<br />
An der stelle hatte ich nicht geguckt weil ich vergessen hatte das ich die da auch habe...</p>
</blockquote>
<p>Ja, genau deswegen tut man ja auch auf den Fehler doppelklicken, und die IDE hüpft netterweise ins richtige File in die richtige Zeile. Dann sieht man das schon <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1306887</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1306887</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Fri, 15 Jun 2007 19:44:42 GMT</pubDate></item></channel></rss>