#1 21 Jan 2017 02:44

fbtg@hc
New Member
Registered: 21 Jan 2017
Posts: 3

Get-Random increased randomness HELP

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

#2 21 Jan 2017 02:47

fbtg@hc
New Member
Registered: 21 Jan 2017
Posts: 3

Re: Get-Random increased randomness HELP

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

#3 21 Jan 2017 23:42

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 893
Website

Re: Get-Random increased randomness HELP

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

#4 23 Jan 2017 23:10

fbtg@hc
New Member
Registered: 21 Jan 2017
Posts: 3

Re: Get-Random increased randomness HELP

How would I call it and use it with the script I'm running?  I'm a self professed noob  roll

Offline

#5 26 Jan 2017 01:19

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 893
Website

Re: Get-Random increased randomness HELP

$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

Board footer

Powered by FluxBB