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 read in a text file containing any number of quotes, will provide a random quote 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.
RandomQuote.ini
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
OnRefreshAction=[!SetOption MeterQuote W "#WidthVar#@#Monitor##"][!SetOption MeterQuote X "(#WidthVar#@#Monitor##/2)"][!UpdateMeter MeterQuote][!Redraw]
[Metadata]
Name=RandomQuote
Author=JSMorley
Description=Pithy quote every 30 seconds, centered on the monitor.
Instructions=Click to copy to clipboard||Double-click text to open text file with quotes. Middle click to refresh.||Set variable "Monitor" to the number of the monitor displayed on.
Version=Mar 18, 2013
License=Creative Commons Attribution-Non-Commercial-Share Alike 3.0
[Variables]
Monitor=2
SecondsBetween=30
WidthVar=#SCREENAREAWIDTH
FontFace=Trebuchet MS
FontSize=11
FontColor=255,255,255,255
[MeasureQuote]
Measure=Script
ScriptFile=RandomQuote.lua
UpdateDivider=#SecondsBetween#
[MeterQuote]
Meter=String
MeasureName=MeasureQuote
FontColor=#FontColor#
FontFace=#FontFace#
FontSize=#FontSize#
StringStyle=Normal
StringAlign=Center
SolidColor=0,0,0,1
AntiAlias=1
LeftMouseUpAction=[!SetClip "[MeasureQuote]"]
LeftMouseDoubleClickAction=["#CURRENTPATH#Pithy.txt"]
MiddleMouseUpAction=!Refresh
DynamicVariables=1
Code: Select all
function Initialize()
quoteTable, currentTable = {}, {}
for line in io.lines(SKIN:MakePathAbsolute('Pithy.txt')) do
table.insert(quoteTable, line)
end
end -- Initialize
function Update()
if #currentTable == 0 then
currentTable = SortRandom(quoteTable)
end
return table.remove(currentTable)
end -- Update
function SortRandom(inputTable)
assert(type(inputTable) == 'table', ('SortRandom must receive a table. Received %s instead.'):format(type(inputTable)))
local sortedTable, unsortedTable = {}, {}
for inc = 1, #inputTable do
table.insert(unsortedTable, inputTable[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 -- SortRandom
- In Initialize(), read the entire text file being used as the source into a table. Get the count of how many items are in the table.
- Create a table (quoteTable) to hold the random numbers, between 1 and the total number of quotes, that have already been used.
- in Update(), check to see if a temporary table (currentTable) created to hold the quotes in a random order is empty.
- If so - Execute the RandomSort() function which will create the temporary table by copying the quotes from quoteTable into it in a random order.
- Remove and return the first quote from the temporary / random table to the skin, for display in the meter.
Each of the quotes 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.