It is currently November 28th, 2022, 3:37 pm

Random Values

Report bugs with the Rainmeter application and suggest features.
User avatar
Alex2539
Rainmeter Sage
Posts: 642
Joined: July 19th, 2009, 5:59 am
Location: Montreal, QC, Canada

Random Values

Post by Alex2539 »

This seems pretty self explanatory to me, but I'll explain it anyways ;). Basically, if I'm typing up the formula for a Calc measure, it would be nice if I could type in RAND to get a random number. It doesn't need to be fancy. If it were just a keyword that generates a random decimal from 0 to 1 (ie: 0.3223 or something like that), it would still be easy enough to work off.

I'm no code monkey, so this may be more complicated than I imagine it is. But if not, then I can think of a dozen uses for this, especially with the features introduced in the latest beta.
ImageImageImageImage
MattKing
Developer
Posts: 98
Joined: August 6th, 2009, 3:03 pm

Re: Random Values

Post by MattKing »

It is super easy to do, in fact I've already implemented in it in my version of rainmeter.

Was about seven lines of code added to MeasureCalc.cpp


Edit:

I must say, the source code is awesomely easy to understand.
sgtevmckay

Re: Random Values

Post by sgtevmckay »

MattKing wrote:It is super easy to do, in fact I've already implemented in it in my version of rainmeter.

Was about seven lines of code added to MeasureCalc.cpp


Edit:

I must say, the source code is awesomely easy to understand.
Could you please post more information regarding this ???
MattKing
Developer
Posts: 98
Joined: August 6th, 2009, 3:03 pm

Re: Random Values

Post by MattKing »

sgtevmckay wrote: Could you please post more information regarding this ???
Hah, I guess I should've explained more but I guess assumed the real devs would've already done it.

I've beefed up what I originally did and I'm gonna post the cpp and h file, they're commented as to what I changed.

ASPLAINED:

The way it works is just like Counter, you just type Random in a formula and Random is replaced with a random number. You can set a LowBound and HighBound with those specific keys. The random number is a whole number.

What I added/edited: 3 private static variables, edited the constructor and the configreader function.

Obviously to use this you would need to compile rainmeter with this edit.


Example measure returns a number from 5-100.

Code: Select all

[MeasureCalcy]
Measure=Calc
Formula=(Random)
LowBound=5
HighBound=100
sgtevmckay

Re: Random Values

Post by sgtevmckay »

Thanks :D
User avatar
jsmorley
Developer
Posts: 22551
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Random Values

Post by jsmorley »

Matt,

I have added your code as a "branch" in our repository so a few of the devs can play with it and make sure it works and plays with the other children ok. Seems to work great on my local compile, does as advertised. I assume Rainy will merge it as soon as he gets a chance to take a look at it.

Nice, nice...

Now I have a pet project I would like you to help with if you feel adventurous. I will create a new topic called "Fonts" in this forum, so we can discuss it and see if you are interested.

Man, it would be GREAT to have someone who can help take some of the load off Rainy on things in the core C++ app.
User avatar
kenz0
Developer
Posts: 263
Joined: July 31st, 2009, 2:23 pm
Location: Tokyo, JPN

Re: Random Values

Post by kenz0 »

Alex2539 wrote:This seems pretty self explanatory to me, but I'll explain it anyways ;). Basically, if I'm typing up the formula for a Calc measure, it would be nice if I could type in RAND to get a random number. It doesn't need to be fancy. If it were just a keyword that generates a random decimal from 0 to 1 (ie: 0.3223 or something like that), it would still be easy enough to work off.

I'm no code monkey, so this may be more complicated than I imagine it is. But if not, then I can think of a dozen uses for this, especially with the features introduced in the latest beta.
Here is another simple solution.
http://www.rainlendar.info/oldforum/phpBB2/viewtopic.php?t=1282

And this is the sample skin which I made using this method.
random.zip
Summary of skin:
- [MeasureRandom1] is a random number generator.
- Just one digit is extracted from the generated number.
- When the specified number appears !RainmeterShowMeter is executed.
[Variables]
HIDEALL=[!RainmeterHideMeter (s1)][!RainmeterHideMeter (s2)][!RainmeterHideMeter (s3)][!RainmeterHideMeter (s4)][!RainmeterHideMeter (s5)][!RainmeterHideMeter (s6)][!RainmeterHideMeter (s7)][!RainmeterHideMeter (s8)][!RainmeterHideMeter (s9)]

[Rainmeter]
BackgroundMode=1
Update=500

[MeasureRandom1]
Measure=Calc
Formula=(MeasureRandom1 = 0) ? ((3141592653 * 5772156649 + 2718281829) % 34359738368) : ((3141592653 * MeasureRandom1 + 2718281829)) % 34359738368
UpdateDivider=0

[MeasureTrunc0]
Measure=CALC
Formula=TRUNC((MeasureRandom1 % (100 * 1000)) / 10000) = 0 ? 1 : 0
IfEqualValue=1
IfEqualAction=!Execute #HIDEALL#[!RainmeterShowMeter (s1)][!RainmeterRedraw]

[MeasureTrunc1]
Measure=CALC
Formula=TRUNC((MeasureRandom1 % (100 * 1000)) / 10000) = 1 ? 1 : 0
IfEqualValue=1
IfEqualAction=!Execute #HIDEALL#[!RainmeterShowMeter (s1)][!RainmeterRedraw]

[MeasureTrunc2]
Measure=CALC
Formula=TRUNC((MeasureRandom1 % (100 * 1000)) / 10000) = 2 ? 1 : 0
IfEqualValue=1
IfEqualAction=!Execute #HIDEALL#[!RainmeterShowMeter (s2)][!RainmeterRedraw]

[MeasureTrunc3]
Measure=CALC
Formula=TRUNC((MeasureRandom1 % (100 * 1000)) / 10000) = 3 ? 1 : 0
IfEqualValue=1
IfEqualAction=!Execute #HIDEALL#[!RainmeterShowMeter (s3)][!RainmeterRedraw]

[MeasureTrunc4]
Measure=CALC
Formula=TRUNC((MeasureRandom1 % (100 * 1000)) / 10000) = 4 ? 1 : 0
IfEqualValue=1
IfEqualAction=!Execute #HIDEALL#[!RainmeterShowMeter (s4)][!RainmeterRedraw]

[MeasureTrunc5]
Measure=CALC
Formula=TRUNC((MeasureRandom1 % (100 * 1000)) / 10000) = 5 ? 1 : 0
IfEqualValue=1
IfEqualAction=!Execute #HIDEALL#[!RainmeterShowMeter (s5)][!RainmeterRedraw]

[MeasureTrunc6]
Measure=CALC
Formula=TRUNC((MeasureRandom1 % (100 * 1000)) / 10000) = 6 ? 1 : 0
IfEqualValue=1
IfEqualAction=!Execute #HIDEALL#[!RainmeterShowMeter (s6)][!RainmeterRedraw]

[MeasureTrunc7]
Measure=CALC
Formula=TRUNC((MeasureRandom1 % (100 * 1000)) / 10000) = 7 ? 1 : 0
IfEqualValue=1
IfEqualAction=!Execute #HIDEALL#[!RainmeterShowMeter (s7)][!RainmeterRedraw]

[MeasureTrunc8]
Measure=CALC
Formula=TRUNC((MeasureRandom1 % (100 * 1000)) / 10000) = 8 ? 1 : 0
IfEqualValue=1
IfEqualAction=!Execute #HIDEALL#[!RainmeterShowMeter (s8)][!RainmeterRedraw]

[MeasureTrunc9]
Measure=CALC
Formula=TRUNC((MeasureRandom1 % (100 * 1000)) / 10000) = 9 ? 1 : 0
IfEqualValue=1
IfEqualAction=!Execute #HIDEALL#[!RainmeterShowMeter (s9)][!RainmeterRedraw]

[(s1)]
Meter=Image
X=0
Y=0
W=20
H=20
SolidColor=FF0000
Hidden=1

[(s2)]
Meter=Image
X=20r
Y=0r
W=20
H=20
SolidColor=00FF00
Hidden=1

[(s3)]
Meter=Image
X=20r
Y=0r
W=20
H=20
SolidColor=0000FF
Hidden=1

[(s4)]
Meter=Image
X=0
Y=20r
W=20
H=20
SolidColor=FF9C00
Hidden=1

[(s5)]
Meter=Image
X=20r
Y=0r
W=20
H=20
SolidColor=FFFC00
Hidden=1

[(s6)]
Meter=Image
X=20r
Y=0r
W=20
H=20
SolidColor=00FFEA
Hidden=1

[(s7)]
Meter=Image
X=0
Y=20r
W=20
H=20
SolidColor=9000FF
Hidden=1

[(s8)]
Meter=Image
X=20r
Y=0r
W=20
H=20
SolidColor=FF00C0
Hidden=1

[(s9)]
Meter=Image
X=20r
Y=0r
W=20
H=20
SolidColor=FFFFFF
Hidden=1
.
Image
User avatar
maminscris
Posts: 509
Joined: April 24th, 2009, 3:17 pm
Location: Bucharest, Romania Lat 44,43° Lon 26,1°

Re: Random Values

Post by maminscris »

wow :shock: this is awesome






except the fact i try to catch the squares with mouse to move the skin for 1 min, maybe a new feature or rainmeter will be to open the skins in the center of the screen instead top left corner
Zero at programing, zero at writing codes, so far 2 at making images
But I'm good at copy/paste, and I not always like this
Image
User avatar
Alex2539
Rainmeter Sage
Posts: 642
Joined: July 19th, 2009, 5:59 am
Location: Montreal, QC, Canada

Re: Random Values

Post by Alex2539 »

I've actually already done something very much like this, except mine was unnecessarily complicated. The only thing that bit of code is missing is a proper seed. Even if on the first run you can't predict what number will come next, if you ran that over and over, you would always get the same first value, second value, third value etc. Changing one of those values with one from a Time measure would do the trick. I used one where the format was something like "%S%H%M%S%M". By the time your code came back around to zero, the time would be completely different.

Still, it would be nice if this were implemented as a single keyword.
ImageImageImageImage
User avatar
jsmorley
Developer
Posts: 22551
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Random Values

Post by jsmorley »

Alex2539 wrote:I've actually already done something very much like this, except mine was unnecessarily complicated. The only thing that bit of code is missing is a proper seed. Even if on the first run you can't predict what number will come next, if you ran that over and over, you would always get the same first value, second value, third value etc. Changing one of those values with one from a Time measure would do the trick. I used one where the format was something like "%S%H%M%S%M". By the time your code came back around to zero, the time would be completely different.

Still, it would be nice if this were implemented as a single keyword.
It is in the trunk and will be in the next full build.