Windows Form application: generate random num.

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
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
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.
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
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
closed account (z05DSL3A)
errm...yeah...or not.
Topic archived. No new replies allowed.