Custom Inventory to return Random Number
I am looking to have a custom inventory that will return a random number. I am planning on using this to slow down some software deployment/updates (namely Dell Command Update). For example, I will only target devices where the random number is between 1 and 20 to update a random subset of our devices. We have roughly 2500 devices, so in the example 1-20, it should target roughly 20 devices given a random number between 1 and 2500. Every time the device would be inventoried, it would change the random number to cycle in new devices to update.
I believe I have come close, but it does not seem to work as id expect.
ShellCommandNumberReturn(cmd /c powershell -command "Get-Random -Minimum 1 -Maximum 2501")
This does not work, it will just not report anything.
ShellCommandTextReturn(cmd /c powershell -command "Get-Random -Minimum 1 -Maximum 2501")
This works, but then when sorting by Random Number, it is ordered in alphabetical order, not numeric. For example: 1,1000,2,23,2500
ShellCommandNumberReturn(cmd /c echo %random%)
This does not work either.
I'd prefer if it was a number between 1 and 2500, but I'll settle for any random number, stored as a number.
Answers (2)
Top Answer
ShellCommandNumberReturn(cmd /c echo %RANDOM%")
The Windows operating system uses a pseudo-random number generator (PRNG) that is considered the most commonly used PRNG. The pseudo-randomness of the output from this generator is important for the security of almost any application running in Windows.
The %RANDOM% pseudovariable in cmd.exe generates a "random" number, but it's not very random. Here are some reasons why:
The %RANDOM% pseudovariable generates the same "random" number until the clock ticks over to the next second.
If two copies of a script are running at the same time, they will both get the same "random" number and mix their output together.