先给一个java的链接,C#的方法类似:
https://www.cnblogs.com/happyday56/p/5163264.html
类似地,一定会有相对应的C#的方式,链接如下:
https://www.jb51.net/article/66255.htm
我自己整理出一个自认为比较简单的方式:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MathTool : MonoBehaviour
{
/// <summary>
/// Gets the random numbers.
/// </summary>
/// <returns>The random numbers.</returns>
/// <param name="min">Minimum.</param>
/// <param name="max">Max.</param>
/// <param name="count">Count.</param>
public static int[] GetRandomNumbersArray(int min, int max, int count)
{
if (count > (max - min + 1) || max < min) {
return null;
}
int[] result = new int[count];
HashSet<int> set = new Has