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.
More specifically, the following is exactly what I'm running.
$dir = Split-Path $MyInvocation.MyCommand.Path
gci "$dir\*" -include $formats | Get-Random -Count 1 |
How would I call it and use it with the script I'm running? I'm a self professed noob
$myrandom = & cscript /nologo "c:\batch\random.js"
will create an array of 10 random numbers which you can then treat like any array variable: