我对 C++ 很陌生,本周要完成一项非常艰巨的任务。我不会详细介绍它,因为我不想为我完成工作,但是谁能指出我将如何从多维字符串数组中选择随机字符的正确方向?
char gameZero[16][6] = { {'A','A','C','I','O','T'}, {'A','H','M','O','R','S'}, {'E','G','K','L','U','Y'}, {'A','B','I','L','T','Y'}, {'A','C','D','E','M','P'}, {'E','G','I','N','T','V'}, {'G','I','L','R','U','W'}, {'E','L','P','S','T','U'}, {'D','E','N','O','S','W'}, {'A','C','E','L','R','S'}, {'A','B','J','M','O','Q'}, {'E','E','F','H','I','Y'}, {'E','H','I','N','P','S'}, {'D','K','N','O','T','U'}, {'A','D','E','N','V','Z'}, {'B','I','F','O','R','X'} };
目标是打印出这些字符的 4x4 棋盘,在每场游戏开始时从每个数组中随机选择一个字符,这样棋盘就不一样了。
任何有关如何执行此操作的建议/提示将不胜感激 - 谢谢!
编辑:
我已经到了可以从两个数组生成随机索引的地步,但是我目前的做法只输出一个字符,而我需要从数组中的 16 个分类中的每个分类中获取一个字符。关于如何从每个输出一个的任何想法?我想我必须将索引生成器放在某种循环中。
mt19937 gen(time(nullptr)); // random number generator
// used to generate random number in specific range
uniform_int_distribution<int> random_outer(0, outer_size - 1);
uniform_int_distribution<int> random_inner(0, inner_size - 1);
int index_outer = random_outer(gen); // used to generate random outer index
int index_inner = random_inner(gen); // used to generate random inner index
cout << gameZero[index_outer][index_inner] << endl;