generate the random number between a to b
2012-09-09 19:35
591 查看
/********************************************************** @brief: generate the random number between a to b **********************************************************/ #include <stdlib.h> #include <stdio.h> #include <time.h> void RangedRandDemo( int range_min, int range_max, int n ) { int i, u; // Seed the random-number generator with the current time so that // the numbers will be different every time we run. srand( (unsigned)time( NULL ) ); for ( i = 0; i < n; i++ ) { //u = rand() % (range_max - range_min + 1) + range_min; //[a,b] //u = rand() % (range_max - range_min ) + range_min; //[a,b) //u = rand() % (range_max - range_min ) + range_min + 1; //(a,b] u = rand() % (range_max - range_min - 1) + range_min + 1; //(a,b] printf( " %6d\n", u); } } int main( void ) { printf("\n"); RangedRandDemo( -2, 2, 10 ); }
相关文章推荐
- (斐波那契总结)Write a method to generate the nth Fibonacci number (CC150 8.1)
- Data migration to generate the maximum value of the sequence between beta scheme and appbeta scheme
- 10 Ways to Generate a Random Password from the Command Line
- How to generate a random number in R
- python int to binary and count the number of 1
- Warning: Unable to determine the number of frames in this file
- Tutorial: Generate BBox or Rectangle to locate the target obejct
- How to apply the Kernel patch & How to generate a Kernel patch
- Lintcode379 Reorder array to construct the minimum number solution 题解
- Modify the average program to promote for intergers repeatedly.stop when a nagetive number is entere
- Ubuntu 安装joomla出错(Could not connect to the database. Connector returned number: The MySQL adap)解决办法
- Unable to determine the principal end of an association between the types '***. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.
- poi导出excel报The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xl
- matlab:Warning: Unable to determine the number of frames in this file.
- How to get random number within a range using C++ - 如何用C++获取一定范围内的随机数
- Use XML Schema Definition Tool to Generate the classes
- The Solution to Leetcode 137 Single Number II
- Could Not Connect To The Specified Instance - MySQL Error Number 2003 - (10061)问题
- Modify the average program to promote for intergers repeatedly.stop when a nagetive number is entere
- What is the difference between << and += while injecting elements to Hash.new([])?