Results 1 to 4 of 4

Thread: Function for two random numbers

  1. #1
    Join Date
    Apr 2009
    Posts
    87

    Function for two random numbers

    I need code to create function for the random selection between two numbers, I looked on the internet for examples of uses, but I did not understand much, but what l want know is that how to use the random number in c program.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Function for two random numbers

    Try this :
    Code:
    int random (int min, int max) (
    	 return (int) (min + ((float) rand () / RAND_MAX * (max - min + 1)));
     )

  3. #3
    Join Date
    Jan 2009
    Posts
    199

    Re: Function for two random numbers

    The key function in generating random numbers is; int random (int n); which generates a random number in the range of 0 to n-1. Random number generators (pseudo-random, of course) in C; mostly fast one-liners for "inline" use (to eliminate call / return overhead). "srand()/rand()" isn't exactly the most sophisticated random number generator in the world.

  4. #4
    Join Date
    Dec 2008
    Posts
    177

    Re: Function for two random numbers

    The random number generator produces a sequence of numbers that gives the appearance of being random, when in fact the sequence will eventually repeat and is predictable. Generating random numbers in C is needed in several applications. For instance, generating a default password for a new user on a network uses random generation of numbers and letters.

Similar Threads

  1. Replies: 4
    Last Post: 13-01-2012, 05:07 PM
  2. C sharp program to print random numbers
    By Prashobh Mallu in forum Software Development
    Replies: 5
    Last Post: 12-01-2010, 12:07 PM
  3. Random Numbers in C
    By Rob Dizzle in forum Software Development
    Replies: 5
    Last Post: 30-12-2009, 10:37 AM
  4. Want an array of Random numbers
    By InterNetWorKed in forum Software Development
    Replies: 4
    Last Post: 03-11-2009, 02:17 PM
  5. Random numbers. Help
    By tetilda in forum Software Development
    Replies: 2
    Last Post: 15-09-2008, 05:52 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,263,712.83145 seconds with 17 queries