Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 317
  • Last Modified:

Create a random number

How do I create a random number in visual studio .net 2005 using managed code?
0
Kranarna
Asked:
Kranarna
  • 4
  • 3
1 Solution
 
AlexFMCommented:
0
 
KranarnaAuthor Commented:
what do you have to include to use the random class, because I cant use?
0
 
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
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
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
 
AlexFMCommented:
>> 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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now