[問題] 如何寫一個亂數產生器,數字不能重覆

看板C_and_CPP (C/C++)作者 (方塊小子)時間13年前 (2012/10/07 09:19), 編輯推噓3(302)
留言5則, 4人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 如何寫一個亂數產生器,數字不重覆? 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版) #include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int c,a; srand(time(NULL)); printf("The ans is :\n"); for(a=1;a<=100;a++) { // srand(time(NULL)); c=rand()%100+1; printf(" %d\t",c); } system("pause"); return 0; } 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.39.0.75

10/07 09:55, , 1F
很多方法啊,我都用系統時間做亂數複雜度
10/07 09:55, 1F

10/07 09:57, , 2F
直接把開機時間拿來當亂數也行
10/07 09:57, 2F

10/07 10:49, , 3F
找精華區的洗牌
10/07 10:49, 3F

10/07 11:31, , 4F
http://0rz.tw/2mPip 最簡單的
10/07 11:31, 4F

10/08 12:33, , 5F
洗牌 取你要的數量
10/08 12:33, 5F
文章代碼(AID): #1GSDYtRO (C_and_CPP)
文章代碼(AID): #1GSDYtRO (C_and_CPP)