Create a random number

How do I create a random number in visual studio .net 2005 using managed code?
KranarnaAsked:
Who is Participating?
 
AlexFMConnect With a Mentor Commented:
>> How do I create a random number in visual studio .net 2005 using managed code?

Your code is unmanaged. Use rand function:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_rand.asp
0
 
AlexFMCommented:
0
 
KranarnaAuthor Commented:
what do you have to include to use the random class, because I cant use?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
AlexFMCommented:
Random class belongs to System namespace, it can be used in any C++/CLI application without additional references.

using namespace System;
...

Random^ r = gcnew Random( 10);
...
0
 
KranarnaAuthor Commented:
This is how my code looks and it doesnt work. Any ideas?

#include <windows.h>
#include <cassert>
#include <cstdio>

int APIENTRY WinMain(
      HINSTANCE instance,
      HINSTANCE previousInstance,
      LPSTR commandLine,
      int commandShow)
{
      Random^ r = gcnew Random( 10);
}
0
 
KranarnaAuthor Commented:
Sorry, thought it was managed, well well.

Thank you!
0
 
AlexFMCommented:
VC++ 8.0 allows to create both managed and unmanaged applications. In Application Wizard, Project Type step, CLI item contains managed applications, all other items (MFC, Win32 ...) are unmanaged applications, like in old VC++ 6.0.
0
All Courses

From novice to tech pro — start learning today.