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

    how can i do it??? urgent.

    Hi guys i just can't write the rand() to return specific number from 0 up to 6.
    Can anybody help me out.

    Thanks alot.


  2. #2
    Guest

    Re: how can i do it??? urgent.

    Try this

    int random = (int)((double)rand()/(double)RAND_MAX * 6.0);

    This should give random numbers from and including 0 up to and
    including 6.



  3. #3
    Guest

    Re: how can i do it??? urgent.

    Why not just:

    int randomValue = rand() % 6;

    That's better than casting all over the place.


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