嗨
这是我如何使用随机数,但它总是给indexOfAChosenListCell提供“1”索引。
当我调试它,它表现出不同的值,但定期运行,每次我得到同样的举动..
什么是随机的问题,这是静态不是随机的... :)Random.Next不给随机数
internal Square getAutomaticMove()
{
List<Square> LegalMovesArray = GetLegalSquares();
Random randomListCell = new Random();
int indexOfAChosenListCell = 0;
if (CheckForLegalSquares())
{
indexOfAChosenListCell = randomListCell.Next(LegalMovesArray.Count-1);
}
提示创建新的对象?另外,移动你的Random的外部构造getAutomaticMove() – 2011-03-27 00:50:31
@Mitch:谢谢你的回答,但是LegalMovesArray.Count-1有什么问题,我想抛弃LegalMovesArray中的一个索引,它没有索引whi等于LegalMovesArray.Count ... – Mulder 2011-03-27 01:04:56