Skip to content

Commit 089ea6f

Browse files
committed
feat(Random): Add choose one
1 parent d1ff02f commit 089ea6f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Assets/JCSUnity/Scripts/Util/JCS_Random.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* $Notice: See LICENSE.txt for modification and distribution information
77
* Copyright (c) 2017 by Shen, Jen-Chieh $
88
*/
9+
using System.Collections.Generic;
910
using UnityEngine;
1011

1112
namespace JCSUnity
@@ -77,5 +78,22 @@ private static float FindDecimalInclude(float num)
7778

7879
return 1.0f / Mathf.Pow(10.0f, str.Length);
7980
}
81+
82+
/// <summary>
83+
/// Choose one object from the list.
84+
/// </summary>
85+
/// <typeparam name="T"> Type of the object. </typeparam>
86+
/// <param name="inArray"> The list or array to choose from. </param>
87+
/// <returns> The chosen object from the list or array. </returns>
88+
public static T ChooseOne<T>(T[] inArray)
89+
{
90+
int index = Range(0, inArray.Length);
91+
return inArray[index];
92+
}
93+
public static T ChooseOne<T>(List<T> inList)
94+
{
95+
int index = Range(0, inList.Count);
96+
return inList[index];
97+
}
8098
}
8199
}

0 commit comments

Comments
 (0)