【发布时间】:2019-02-26 02:16:48
【问题描述】:
我想在 1 到 50 个口袋妖怪之间随机选择,但rand 只选择数组中的第 42 个(Dragonite)。我怎样才能让它变得随机?
#include <stdlib.h>
#include <stdio.h>
int main(){
char sorteio1[50][11] = {"Bulbasaur","Venusaur","Charmander","Charmeleon","Charizard","Pidgey","Pidgeotto","Pidgeot","Pikachu","Raichu","Clefairy","Vulpix","Ninetales","Meowth","Psyduck","Golduck","Mankey","Primeape","Growlithe","Arcanine","Abra","Kadabra","Alakazam","Magnemite","Magneton","Onix","Cubone","Marowak","Staryu","Starmie","MrMime","Jynx","Magikarp","Gyarados","Lapras","Ditto","Eevee","Vaporeon","Porygon","Snorlax","Dragonair","Dragonite","Mewtwo","Mew","Chikorita","Sentret","Furret","Hoothoot","Lanturn","Pichu"};
int i;
i = rand() %50;
printf ("%s\n",sorteio1[i]);
system ("Pause");
return 0;
}
【问题讨论】:
-
这个网站是英文的,也许你想要Stack Overflow em Português?
-
我不知道那是西班牙语还是葡萄牙语。你可能想在es.stackoverflow.com 或pt.stackoverflow.com 发帖。