【代码如下】
public class MyModel
{
public int index { get; set; }
public string name { get; set; }
public string desc { get; set; }
}
public ActionResult Index()
{
//先是顺序数字
List<MyModel> indexList = new List<MyModel>();
for (int i = 0; i < 10; i++)
{
indexList.Add(new MyModel() { index = (i + 1), name = "有趣功能", desc = "这是一个神奇的公众号" });
}
//打乱顺序
List<MyModel> indexListNew = new List<MyModel>();
for (int i = indexList.Count - 1; i >= 0; i--)
{
int currentIndex = RandomHelper.GetNumByValue(0, i);
indexListNew.Add(indexList[currentIndex]);
indexList.RemoveAt(currentIndex);
}
}