Slow down rand function

I’m following this, you guys rock :sunglasses:

3 Likes

I WAS WRONG THIS DOESN’T WORK! I’m going to keep going, maybe something will come of it.

Ok, you all ready for something crazy? Behold! Random number formula 2.0!

(floor((pi*(floor(((#DWFS#/30)+wakeRand(0,100)))))%10)+1)

Dropped the exp() function as pi is random enough and exp() caused some bugs from time-to-time.
Lets break it down:

(floor((pi*(floor(((#DWFS#/C)+wakeRand(D)))))%A)+B)

A: This is how many numbers you want to choose from. Its not the maximum, I’ll explain in a bit, but safe to say if you want 10 numbers in your range, set this to 10, 100 numbers, set this to 100. Easy, right?

B: This is the starting number for your range. If this is set to 0, your range starts at 0, 1 starts your range at 1, and so on. So, if you want a number from 1 to 10, set A to 10 and B to 1. If you want 0 to 9, set A to 10 and B to 0. If you want 20 to 25, set A to 6 and B to 20. Set A at 11, B at -5, you get -5 to 5. Get it?

C: This controls how often you get a new random number. The timer is based off the #DWFS# (second hand angle) tag, which goes from 0 to 359.99… every minute. Basically, you figure out how many times you want the numbers to change each minute and divide it out. The formula I posted has 30 here. 360/30 = 12. 60/12 = 5, so this will update once every 5 seconds. In preview mode it sometimes jumps a bit, but I think that’s just down to how the editor can be a little glitchy at times as it seems to work perfectly on the watch itself. If you don’t want to do the math yourself, I’ll put the values needs for each division below. Keep in mine it will always give a new number after a it hits the minute mark since #DWFS# will reset to 0, so its best to pick value that divide evenly into 360.

D: This is kind of like the seed value for a rand() function in coding. I needed some way to pass in a new, arbitrary number each time the watch woke up or it would always be the same pattern. In coding, programmers usually use the current timestamp, but I can’t do that here as it constantly updates, so the number would be changing just as fast as rand() currently does. wakeRand() to the rescue! This will only give a new number ever time the watch wakes up, perfect for our needs. The only issue is if you have need for multiple random numbers, you need to set this range to a different value for each generator, and you don’t want them to overlap. This is due to a weird fluke of how wakeRand() functions. Failing to do so will make you wind up with both numbers being the same at all times. Even if your range of random numbers is different you’ll see weird things, like if 1-10 gives 2, 1-50 will give you 42 every time, or something like that. Point is the numbers will be correlated. So for my project, I set the first one to wakeRand(0,99), next one (100,199), next one (200,299), etc. Edit: Of course, there may be circumstances where you WANT to have the formula get the same number in each copy, in that case just use the exact same formula in each element, with the same wakeRand() and all that. This is a good way to randomly change an image on a set schedule. Just base each images Opacity on the result of the formula. :wink:
Like so:
Image 1: $(floor((pi*(floor(((#DWFS#/30)+wakeRand(0,100)))))%10)+1)=1?100:0$
Image 2: $(floor((pi*(floor(((#DWFS#/30)+wakeRand(0,100)))))%10)+1)=2?100:0$
Image 3: $(floor((pi*(floor(((#DWFS#/30)+wakeRand(0,100)))))%10)+1)=3?100:0$
etc.

Ok, sorry for the huge post, but hopefully someone aside from me finds this useful/interesting! Thanks again to @russellcresser for lending a hand and letting me bounce ideas off them. I’ll be posting a Watch-face here in a bit that uses this. All this talk of random got me inspired to do something other than the original idea I had, so I bashed it out as a sort of test/proof of concept.

C values for Random Delay:

Seconds to delay C value to use Divides Evenly?
1 6 Yes
2 12 Yes
3 18 Yes
4 24 Yes
5 30 Yes
6 36 Yes
7 42
8 48
9 54
10 60 Yes
11 66
12 72 Yes
13 78
14 84
15 90 Yes
16 96
17 102
18 108
19 114
20 120 Yes
21 126
22 132
23 138
24 144
25 150
26 156
27 162
28 168
29 174
30 180 Yes
31 186
32 192
33 198
34 204
35 210
36 216
37 222
38 228
39 234
40 240
41 246
42 252
43 258
44 264
45 270
46 276
47 282
48 288
49 294
50 300
51 306
52 312
53 318
54 324
55 330
56 336
57 342
58 348
59 354
60 360 Yes

Lastly, just in case anyone wondered how well it simulated randomness, I ran this for 1000 “rolls” and here’s the results (perfect distribution would mean probability at 10%, which we approach at 1000, more “rolls” would likely get us even closer):

Result 1 2 3 4 5 6 7 8 9 10 AVG
Count 96 103 97 103 99 100 100 98 101 103 100
Diff from Average -4 3 -3 3 -1 0 0 -2 1 3
Probability 9.6% 10.3% 9.7% 10.3% 9.9% 10.0% 10.0% 9.8% 10.1% 10.3%
4 Likes

Woah, pretty good stuff there @adamalbee1984! Very nice & thanks for describing it so well.
This will surely come in handy for a couple of preliminary faces I got started a while ago in the background. I can see you are going to be a handy resource around here, welcome to the community! :+1::+1::+1:

3 Likes

Thanks, I just decided to be too stubborn to give up on this!

2 Likes

Nothing to see here…

2 Likes

Very cool! That could come in handy for a board game player. Just look at your watch and you can see your roll, no matter the game. :+1: By the way, might want to move the time to the top layer and make it a bit bigger… Just a thought.
I know the feeling about being too stubborn, until the thing that needs figuring is fully figured. :grin:
I could have used that formula when I made my magic 8 ball face a long while back…

For this I just had 9 text elements with the following in the opacity box:
$wakeRand(0,9)=A?100:0$
where each box with the random text element had the numbers 0-9 substitued for A.
I also put the following in the X coordinate box
$(#DWE#)>2.5?165:2000$
So that it would shift it into the right position after 2.5 seconds of turning the watch on.
Hit the AOD button (circle with dots around it) 2x to reset.

1 Like

And hmmm, looks like I introduced a bug somewhere as now its producing predictable results, ugh… Not sure what I changed, haha. Gotta dig around a bit.

1 Like

Ha Ha . Ask later .

Your Probability Results look good . I was going to Do an I Ching thing some time ago I might revive it now . Love the Gaming Dice Face .

Well crud, looks like I got too excited, doesn’t work :stuck_out_tongue:
Keeping this here while I fiddle in case it inspires anyone else. What I meant to do is pull a digit of pi, I completely messed that up in the formula and didn’t even notice cuz it seemed like it was working, once I saw my simple mistake, I went to fix it and ran into a problem, the watch simply can’t handle the number of digits needed to have a pattern of more than a few digits of pi. Back to the very messy drawing board.

1 Like

@adamalbee1984 #DNOW# is an Intresting number. Running the Unix Epoc Timer in Milliseconds. That will not repeat for a few hundred years. The problem is without being able to capture something to a variable we are a bit stuck. I was looking at a rand rand but it is a deminishing return.

Just thinking aloud, would it not be possible to use “floor(timestamp/(y*1000))” as it only changes once in y seconds?

2 Likes

Well spotted. Sorry I did not read all the words.

Since the watch is only on for a few seconds, why not use the wakeRand(0,6) function? Even in AOD mode it won’t be refreshing the screen enough to show the random number until you wake it. Generating a new number every 3 seconds is kind of pointless isn’t it?

1 Like

Well, yes, for the Dicebox thing its not really needed. My original goal was for using this for random images to create an animation. I just threw together the Dicebox face to show the formula working. I can fake what I need, but now I’m determined to get this working in a reasonable fashion, mostly out of spite at this point, haha.

1 Like

That would work too, but so far that’s the easy part. Might do that to make setting the delay easier in the final version. My main reason for going the route I did was to keep the numbers a bit smaller, as the facer watch seems to have fits with extremely large numbers, but that might not be a problem going forward. I think I’m getting close to a solution, but don’t wanna jump the gun just in case.

2 Likes

I don’t think big numbers are a problem . I think all the maths is done to 16 bit . If you round something it is only for the display .
There is #DSYNC# Time stamp on sync but I get no useful number from it number from it .

1 Like