You are not logged in.
Pages: 1
Hello all. I am in need of a little help as to increasing the randomness of get-random
I have been using this
PS C:> $files = dir -path c:\* -recurse
PS C:> $sample = $files | get-random -count 1
My application is to have a in home virtual television channel that randomly selects 1 file from multiple folders at 6am and plays them all day until midnight, powers off and starts up, repeating the process daily. The problem I am finding is that whatever the get-random command uses had a tendency to choose the exact same file often. Thus after months of running this script, I am seeing the exact same movies chosen day after day and some that are never chosen.
Is there a way to increase the odds of getting a broader selection of files .mpg's in this instance and less of a repeat of the same .mpg's chosen?
My other option was to find a script that would keep track of the .mpg's chosen and "mark" them, or sort by date accessed and not play the same file twice, until all files of a particular folder have been played once; then "unmarking" all the files and start over. To me that sounds like advanced scripting that I just don't have the knowledge to procure on my own.
Any insight into my dilemma would be vastly appreciated. Any questions about my specifics to help you ascertain a conclusion to this query will be forthcoming.
Cheers!
Offline
ADDENDUM:
More specifically, the following is exactly what I'm running.
$formats =
@("*.mpg")
$dir = Split-Path $MyInvocation.MyCommand.Path
gci "$dir\*" -include $formats | Get-Random -Count 1 |
Invoke-Item
Offline
Not pure powershell but the Alea() random number generator can be used to solve this, you can of course call it from Powershell
See this link
https://ss64.com/nt/syntax-random.html
Offline
How would I call it and use it with the script I'm running? I'm a self professed noob
Offline
$myrandom = & cscript /nologo "c:\batch\random.js"
will create an array of 10 random numbers which you can then treat like any array variable:
$myrandom[4]
Offline
Pages: 1