c++中关于随机数的一个题目

来源:百度知道 编辑:UC知道 时间:2024/05/14 10:31:12
看不懂啥意思,哪位高手翻译并给出答案一下,多谢:
5) Random numbers can be generated using formula:
Number=shiftingValue+rand()%scalingFactor;
Where shiftingValue is equal to the first number in the desired range of consecutive integers and scalingFactor is equal to the width of the desire range of consecutive integers.Write a formula for generating numbers between 7 and 11(both 7and 11 included).

函数实现如下:
#include<iostream.h>
#include <time.h>
#include <stdlib.h>
void main()
{
srand((unsigned)time(NULL));
int i;
i=rand()%5+7;
cout<<i<<endl;
}

产生一个有范围的随机数
他最后叫你产生一个公式
能随机生成7~11的数字(包括7 和 11)
scalingFactor=11-7+1
shiftingValue=7
所以
Number=7+rand()%5