The fewer the number of items in total, the more likely it is to repeat one, but there is never any guarantee, just the "odds", that it won't.
This quote skin shows how you can use a Lua script to overcome this minor limitation. What it will do is use the FileView plugin to index any number of images from some folder(s), will provide a random image on each update, and keep track of what has already been used so it won't repeat any of them until all of them have been displayed.
RandomImage.ini
Code: Select all
[Rainmeter]
Update=1000
[Metadata]
Name=RandomImage
Author=JSMorley
Information=Displays a random non-repeating image from folder tree defined in [Variables] ImagePath.
License=Creative Commons Attribution-Non-Commercial-Share Alike 3.0
Version=Mar 21, 2013
[Variables]
ImagePath="C:\Users\Jeffrey\Pictures"
SecondsBetween=30
[MeasureFolder]
Measure=Plugin
Plugin=FileView
Recursive=2
Path=#ImagePath#
Extensions=jpg;png;bmp
FinishAction=[!EnableMeasure MeasureRandom][!ShowMeter MeterBackground]
[MeasureCount]
Measure=Plugin
Plugin=FileView
Path=[MeasureFolder]
Type=FileCount
[MeasureRandom]
Measure=Script
ScriptFile=RandomImage.lua
Disabled=1
UpdateDivider=#SecondsBetween#
[MeasureImagePath]
Measure=Plugin
Plugin=FileView
Path=[MeasureFolder]
Type=FilePath
IgnoreCount=1
Index=[MeasureRandom]
DynamicVariables=1
[MeterBackground]
Meter=Image
W=210
H=135
SolidColor=60,60,60,170
Hidden=1
[MeterImage]
Meter=Image
W=200
H=125
X=5
Y=5
MeasureName=MeasureImagePath
PreserveAspectRatio=1
TooltipText=[MeasureImagePath]
LeftMouseUpAction=["[MeasureImagePath]"]
DynamicVariables=1
Code: Select all
function Initialize()
msMeasureCount = SKIN:GetMeasure("MeasureCount")
currentTable = {}
end -- Initialize
function Update()
fileCount = msMeasureCount:GetValue()
if #currentTable == 0 then
currentTable = RandomOrder(fileCount)
end
return table.remove(currentTable)
end -- Update
function RandomOrder(inputCount)
assert(type(inputCount) == 'number', ('RandomOrder must receive a number. Received %s instead.'):format(type(inputCount)))
local sortedTable, unsortedTable = {}, {}
for inc = 1, inputCount do
unsortedTable[inc] = inc
end
math.randomseed(tonumber(tostring(os.time()):reverse():sub(1,6)))
while #unsortedTable > 0 do
table.insert(sortedTable, table.remove(unsortedTable, math.random(1, #unsortedTable)))
end
unsortedTable = nil
return sortedTable
end -- RandomOrder
- in Update(), get the total count of files indexed by the FileView plugin measure.
- Check to see if a temporary table (currentTable) created to hold the random numbers between 1 and that total count is empty.
- If so - Execute the RandomOrder() function which will create the temporary table by placing the numbers between 1 and the total count in it in a random order.
- Remove and return the first index number from the temporary / random table to the skin, for display in the meter.
Each of the images from the folder(s) will be used in a random order, never repeating until all of them have been used. Then it will start over. Feel free to ask any questions about how / what this is doing.