怎么用rand函数写以下程序
举个例子,1,2,3,4 出现的概率各是%10,%20,%30,%40 ,根据概率随机输出一个数,只输出一个,请高手指教
#include <stdio.h> #include <stdlib.h> #include <time.h> int main(void) { srand(time(0)); switch (rand() % 10) { case 0: printf("1\n"); break; case 1: case 2: printf("2\n"); break; case 3: case 4: case 5: printf("3\n"); break; case 6: case 7: case 8: case 9: printf("4\n"); break; } return 0; }