CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Randomize

  1. #1
    Join Date
    Aug 2000
    Posts
    670

    Question Randomize

    How do I do Randomize in C#?

  2. #2
    Join Date
    Feb 2003
    Location
    Oklahoma City, OK
    Posts
    63
    you would use System.Random class, you can seed the value to make it more random by using the overloaded constructor Random(int) like the current time in seconds for instance. and to return a random value once u have an instance of the class use the Next method ex:

    Random rand = new Random();

    rand.Next();

    or

    rand.Next(maxvalue);

    or

    rand.Next(minvalue, maxvalue);

  3. #3
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    example,
    you can instantiate Random class by

    Random RA = new Random();
    or
    Random RA = new Random(15);


    and further use to get the new seed

    int num = ra.Next();


    Paresh
    - Software Architect

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured