Solved

Create a random number

Posted on 2006-11-30
7
309 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 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