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

## Random Values

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

### Random Values

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.
MattKing
Developer
Posts: 98
Joined: August 6th, 2009, 3:03 pm

### Re: Random Values

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

Edit:

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

### Re: Random Values

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

Edit:

I must say, the source code is awesomely easy to understand.
MattKing
Developer
Posts: 98
Joined: August 6th, 2009, 3:03 pm

### Re: Random Values

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

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

### Re: Random Values

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.
kenz0
Developer
Posts: 263
Joined: July 31st, 2009, 2:23 pm
Location: Tokyo, JPN

### Re: Random Values

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.
.
maminscris
Posts: 509
Joined: April 24th, 2009, 3:17 pm
Location: Bucharest, Romania Lat 44,43° Lon 26,1°

### Re: Random Values

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
Alex2539
Rainmeter Sage
Posts: 642
Joined: July 19th, 2009, 5:59 am

### Re: Random Values

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.
jsmorley
Developer
Posts: 22551
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

### Re: Random Values

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.