Solved

Create a random number

Posted on 2006-11-30
7
297 Views
Last Modified: 2013-12-03
How do I create a random number in visual studio .net 2005 using managed code?
0
Comment
Question by:Kranarna
  • 4
  • 3
7 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 18048509
0
 

Author Comment

by:Kranarna
ID: 18048610
what do you have to include to use the random class, because I cant use?
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 18051690
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:Kranarna
ID: 18052023
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
 
LVL 48

Accepted Solution

by:
AlexFM earned 50 total points
ID: 18052835
>> 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
 

Author Comment

by:Kranarna
ID: 18053297
Sorry, thought it was managed, well well.

Thank you!
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 18053369
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question