我目前正在做一个小项目只是为了好玩,我正在制作小型随机生成的人civ.Im目前正在处理名称生成的功能,我无法找到一个好方法,或完美的方式来完成这个任务。到目前为止,这就是我所拥有的:
public void GenerateName() {
string[] nameComponent1 = new string[] {"Ge","Me","Ta","Bo","Ke","Ra","Ne","Mi" };
string[] nameComponent2 = new string[] {"oo","ue","as","to","ra","me","io","so" };
string[] nameComponent3 = new string[] {"se.","matt.","lace.","fo.","cake.","end." };
string nameCompfirst = nameComponent1[Random.Range(0, nameComponent1.Length)].ToString();
string nameCompSecond = nameComponent2[Random.Range(0, nameComponent2.Length)].ToString();
string nameCompThird = nameComponent3[Random.Range(0, nameComponent3.Length)].ToString();
}
};
如果你能够为我解决这个问题,那就太棒了 - 或者如果你有更好的建议,那就去吧。我想要的是
由于
答案 0 :(得分:1)
您想使用System.Random类,但在您的代码中,它使用UnityEngine.Random,将其添加到您的类的顶部
KeyError Traceback (most recent call last)
<ipython-input-23-5737d4d13b9f> in <module>()
1 df = pd.DataFrame()
----> 2 pd.read_excel('2016-08-15–2016-08-21.xlsx')
C:\Users\Twentyouts\Anaconda3\lib\site-packages\pandas\io\excel.py in read_excel(io, sheetname, header, skiprows, skip_footer, index_col, names, parse_cols, parse_dates, date_parser, na_values, thousands, convert_float, has_index_names, converters, true_values, false_values, engine, squeeze, **kwds)
189
190 if not isinstance(io, ExcelFile):
--> 191 io = ExcelFile(io, engine=engine)
192
193 return io._parse_excel(
C:\Users\Twentyouts\Anaconda3\lib\site-packages\pandas\io\excel.py in __init__(self, io, **kwds)
247 self.book = xlrd.open_workbook(file_contents=data)
248 elif isinstance(io, compat.string_types):
--> 249 self.book = xlrd.open_workbook(io)
250 else:
251 raise ValueError('Must explicitly set engine if not passing in'
C:\Users\Twentyouts\Anaconda3\lib\site-packages\xlrd\__init__.py in open_workbook(filename, logfile, verbosity, use_mmap, file_contents, encoding_override, formatting_info, on_demand, ragged_rows)
420 formatting_info=formatting_info,
421 on_demand=on_demand,
--> 422 ragged_rows=ragged_rows,
423 )
424 return bk
C:\Users\Twentyouts\Anaconda3\lib\site-packages\xlrd\xlsx.py in open_workbook_2007_xml(zf, component_names, logfile, verbosity, use_mmap, formatting_info, on_demand, ragged_rows)
831 x12sheet = X12Sheet(sheet, logfile, verbosity)
832 heading = "Sheet %r (sheetx=%d) from %r" % (sheet.name, sheetx, fname)
--> 833 x12sheet.process_stream(zflo, heading)
834 del zflo
835
C:\Users\Twentyouts\Anaconda3\lib\site-packages\xlrd\xlsx.py in own_process_stream(self, stream, heading)
546 for event, elem in ET.iterparse(stream):
547 if elem.tag == row_tag:
--> 548 self_do_row(elem)
549 elem.clear() # destroy all child elements (cells)
550 elif elem.tag == U_SSML12 + "dimension":
C:\Users\Twentyouts\Anaconda3\lib\site-packages\xlrd\xlsx.py in do_row(self, row_elem)
743 else:
744 bad_child_tag(child_tag)
--> 745 value = error_code_from_text[tvalue]
746 self.sheet.put_cell(rowx, colx, XL_CELL_ERROR, value, xf_index)
747 elif cell_type == "inlineStr":
KeyError: None
答案 1 :(得分:0)
如果我真的了解你:
Random r = new Random();
string[] nameComponent1 = new string[] {"Ge","Me","Ta","Bo","Ke","Ra","Ne","Mi" };
string[] nameComponent2 = new string[] {"oo","ue","as","to","ra","me","io","so" };
string[] nameComponent3 = new string[] {"se.","matt.","lace.","fo.","cake.","end." };
string nameCompfirst = nameComponent1[r.Next(0, nameComponent1.Length)];
string nameCompSecond = nameComponent2[r.Next(0, nameComponent1.Length)];
string nameCompThird = nameComponent3[r.Next(0, nameComponent1.Length)];
string result = nameCompfirst + nameCompSecond + nameCompThird;