Windows Form application: generate random num.

Apr 4, 2011 at 5:57am
I'm new at C++ and I'm doing a project using the "windows form application" in C++ . Can anyone tell me how to generate random numbers. My idea is that when you click the button the label will display the random number.
Also pls. help me find tutorials for C++ using windows form application all I can see is win32. Thank you.
Last edited on Apr 4, 2011 at 5:58am
Apr 4, 2011 at 8:01am
closed account (z05DSL3A)
Can anyone tell me how to generate random numbers. My idea is that when you click the button the label will display the random number.
1
2
3
4
5
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
{
    Random ^ rnd = gcnew Random;
    label1->Text = rnd->Next().ToString();
}


Random Class: http://msdn.microsoft.com/en-us/library/ts6se2ek.aspx

PS:
"windows form application" is C++/CLI not C++. While it is possible to mix the two in the same project it is not desirable unless the aim of the project is to put unmanaged code into a managed wrapper.
Last edited on Apr 4, 2011 at 8:09am
Apr 4, 2011 at 8:51am
Thank you very much grey wolf. :)
One more question. . . is there a for loop or any loop that I can use in C++/CLI. Thank you again.
Apr 4, 2011 at 9:14am
closed account (z05DSL3A)
General flow control in C++/CLI is the same as C++, (For loops, while loops,...).

I have had a quick look for a tutorial on MSDN, but have not found one yet. (if I get a bit of time later I'll look again).


This article may be of interest:
http://msdn.microsoft.com/en-us/magazine/cc163681.aspx
Last edited on Apr 4, 2011 at 9:41am
Apr 4, 2011 at 2:22pm
Just use RtlGenRandom Function exported from advapi32.dll (xp or later). This will work in any programming language.
http://msdn.microsoft.com/en-us/library/aa387694(v=vs.85).aspx
Apr 4, 2011 at 2:45pm
closed account (z05DSL3A)
errm...yeah...or not.
Topic archived. No new replies allowed.