random file
This commit is contained in:
		
							parent
							
								
									bb3a2d2de3
								
							
						
					
					
						commit
						0655e6a1ee
					
				| 
						 | 
				
			
			@ -0,0 +1,16 @@
 | 
			
		|||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"math/rand"
 | 
			
		||||
	"os"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func getRandomFile(dir string) (string, error) {
 | 
			
		||||
	files, err := os.ReadDir(dir)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return "", err
 | 
			
		||||
	}
 | 
			
		||||
	randomIndex := rand.Intn(len(files))
 | 
			
		||||
	randomImg := files[randomIndex]
 | 
			
		||||
	return dir + "/" + randomImg.Name(), nil
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue