Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 03-12-2009
Member
 
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.
Reply With Quote
  #2  
Old 03-12-2009
Member
 
Join Date: May 2008
Posts: 2,293
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)));
 )
Reply With Quote
  #3  
Old 03-12-2009
Member
 
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.
Reply With Quote
  #4  
Old 03-12-2009
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Function for two random numbers"
Thread Thread Starter Forum Replies Last Post
Generate some quality of random number via Random Number Generation function aMADeO! Windows Software 4 13-01-2012 05:07 PM
C sharp program to print random numbers Prashobh Mallu Software Development 5 12-01-2010 12:07 PM
Random Numbers in C Rob Dizzle Software Development 5 30-12-2009 10:37 AM
Want an array of Random numbers InterNetWorKed Software Development 4 03-11-2009 02:17 PM
Random numbers. Help tetilda Software Development 2 15-09-2008 05:52 PM


All times are GMT +5.5. The time now is 01:11 PM.