Solved

Create a random number

Posted on 2006-11-30
7
291 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

810 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