get random file in directory csharp

Code Example - get random file in directory csharp

                
                        using System.IO;
using System.Collections;

var files = Directory.GetFiles("C:/path_example/example", "*.png"); //.png can be changed to match any other desired extentions
string randomFilePath= files[Random.Range(0,files.Length)];
//example output: "C:/path_example/example/pig4.png"