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

Threaded View

  1. #1
    Join Date
    Oct 2009
    Posts
    40

    Generating big random numbers in C

    I want to generate big random numbers in C(not C++ please).By "big" I mean integers much bigger than srand(time(NULL)) and rand() functions' limit(32767).

    I tried writing: (note:I am not able to see "code" tag button in this editor,so I am not using it)

    //****

    int randomnumber;
    srand( time(NULL) );
    randomnumber = (( rand() % 33 ) * ( rand() % 33 ) * ( rand() % 33) * ( rand() * 33) * (rand() % 33 )) + 1

    //****

    But I have doubts about it's randomness quality.Also there is another problem,the program can't know the maximum random number it should use before user input,so maximum random number may need to use much smaller maximum random number according to user input.

    Is there a better algorithm to create quality big random numbers in C?
    Last edited by AwArEnEsS; February 15th, 2013 at 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
  •  





Click Here to Expand Forum to Full Width

Featured