Results 1 to 7 of 7
  1. #1

    Default C# random: pls help.


    uhmm.. usaon pag gamit ug random integer numbers sa C#? pde ba ma return ang value para ma store ug variable?

    pde post ninyo inyong sample code? hehehe

  2. #2
    The following code returns a random number:

    int num = random.Next();

    The following code returns a random number less than 1000.

    int num = random.Next(1000);

    The following code returns a random number between min and max:

    private int RandomNumber(int min, int max)
    {
    Random random = new Random();
    return random.Next(min, max);
    }

  3. #3
    salamat bai deathnote.

    but naa npud ko lain problem...

    mao ni ako gi try nga code:

    int a=0;
    while(a <= 5)
    {

    int x = new Random().Next(1, 100);
    Console.WriteLine(x);
    a++;

    }

    sa 5 randoms, same ra ang output tanan sa iyang gi first random. i tot coincidence ra but ako gi try ka 10 times, mao man jud.

    unsaon diay pag butang ang random sa loop?

    patabang ko pls.

  4. #4
    you can use this:
    or try to seed it.

    int a=0;
    Random r = new Random();
    while (a <= 5)
    {
    int x = r.Next(1, 100);
    Console.WriteLine(x);
    a++;
    }

  5. #5
    int x = new Random().Next(1, 100);

    yup the prob with ur code is that x should not be initialize as int but as random..and u initialize it outside the loop cause it would be redundant to do it over and over again...thas what the .Next is for.

  6. #6
    Use merssienne twister algorithm if you intend to get a real random number if C#'s random doesnt cut it.

  7. #7
    ah.. okies, ksabot na jud ko. thanks mga bossing.
    Last edited by Gray_Fox; 09-30-2009 at 12:46 AM.

  8.    Advertisement

Similar Threads

 
  1. Replies: 26
    Last Post: 10-17-2005, 09:09 PM
  2. Azureus port value..pls help me
    By benz_jie2005 in forum Software & Games (Old)
    Replies: 3
    Last Post: 09-28-2005, 10:34 AM
  3. ???pls help
    By kyleokita in forum Gizmos & Gadgets (Old)
    Replies: 3
    Last Post: 09-07-2005, 12:03 AM
  4. PLS HELP ME MGA SAMSUNG D500 USERS!!
    By blue_orange in forum Gizmos & Gadgets (Old)
    Replies: 6
    Last Post: 08-25-2005, 10:54 PM
  5. junk shops address in cebu..pls help
    By nikkolai in forum Support Center
    Replies: 2
    Last Post: 07-06-2005, 08:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top