[問題] 如何產生範圍 10^-7 ~ 10^-6 的亂數
※ 引述《akka5678 ()》之銘言:
: 開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
: 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
: 問題(Question):
: 餵入的資料(Input):
: 預期的正確結果(Expected Output):
: 錯誤結果(Wrong Output):
: 程式碼(Code):(請善用置底文網頁, 記得排版)
: 補充說明(Supplement):
: 各位大神
: 我想要產生10^-7~10^-6之間的亂數
: 但rand似乎無法到這麼多
: 是否能詳細的教我
: 感謝
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int a;
double b;
srand(time(NULL));
a=(rand()%901)+100;
b=a/1000000000;
printf("Number is %f.\n",b);
}
我是用除的試試看
但不知道哪裏有錯
每次都產生0
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 101.15.203.83
推
08/09 18:49, , 1F
08/09 18:49, 1F
→
08/09 18:50, , 2F
08/09 18:50, 2F
→
08/09 18:50, , 3F
08/09 18:50, 3F
→
08/09 18:51, , 4F
08/09 18:51, 4F
→
08/09 19:03, , 5F
08/09 19:03, 5F
→
08/09 19:03, , 6F
08/09 19:03, 6F
→
08/09 20:40, , 7F
08/09 20:40, 7F
→
08/09 20:50, , 8F
08/09 20:50, 8F
→
08/11 16:31, , 9F
08/11 16:31, 9F
→
08/11 16:32, , 10F
08/11 16:32, 10F
推
08/11 16:45, , 11F
08/11 16:45, 11F
→
08/11 18:40, , 12F
08/11 18:40, 12F