Android Question Rnd function gives upper half of numbers only

swabygw

Active Member
Licensed User
Longtime User
Please consider following code:

B4X:
' the initializer: noteTimer.Initialize("noteTimer", 1)

Sub noteTimer_Tick()
    
    'ThisBeatTime = DateTime.Now
    Dim DTN As Long = DateTime.Now
    Dim BPM As Int = GetBPM
    Dim TIM As Int = 60000 / BPM
    Dim ERROR_ADJUSTMENT As Int = 25 'arbitrary value to compensate for inaccurate ticker
    
    If DTN >= ((LastBeatTime - ERROR_ADJUSTMENT) + TIM) Then
        '--------------------------------------
        ' Looping characteristics
        '--------------------------------------
        errorTime = DTN - (LastBeatTime + TIM)
        Log("#" & currentKeyCount & ", ErrorTime: " & errorTime & ", DTN: " & DTN & ", LastBeatTime: " & LastBeatTime & ", BPM: " & BPM & ", TIM: " & TIM)
        LastBeatTime = DTN - errorTime

    End If
    
End Sub

Sub GetBPM As Int
    
    Dim BPM_Out As Int
    
    Try
        
        'BPM_Out = lbl_Rate.Text
        
        'If rsb.SelectedMaxValue <> rsb.SelectedMinValue Then
            'BPM_Out = Rnd(rsb.SelectedMinValue, (rsb.SelectedMaxValue + 1))
            BPM_Out = Rnd(1, (100 + 1))
            'Log("BPM: " & BPM_Out)
        'End If
        
    Catch
        Log(LastException)
    End Try
    
    Return BPM_Out
    
End Sub

...produces BPM_Out always between 70 and 100, even though it should be picking between 1 and 100. Why wouldn't there be any random number generated below 70? Is there an error in the initialization maybe?
 
Solution
That was it. I moved the TIM declaration to Globals, added "TIM = (60000 / GetBPM)" inside of the loop (instead of before the loop), and it worked better.

alwaysbusy

Expert
Licensed User
Longtime User
I tried your code and seems fine to me. I get all kind of values for BPM:

B4X:
#, ErrorTime: 1706743178712, DTN: 1706769942615, LastBeatTime: 26763124, BPM: 77, TIM: 779
#, ErrorTime: 1706743177714, DTN: 1706769942617, LastBeatTime: 26763903, BPM: 60, TIM: 1000
#, ErrorTime: 1706743174859, DTN: 1706769942619, LastBeatTime: 26764903, BPM: 21, TIM: 2857
#, ErrorTime: 1706743171704, DTN: 1706769942621, LastBeatTime: 26767760, BPM: 19, TIM: 3157
#, ErrorTime: 1706743170128, DTN: 1706769942623, LastBeatTime: 26770917, BPM: 38, TIM: 1578
#, ErrorTime: 1706743169524, DTN: 1706769942625, LastBeatTime: 26772495, BPM: 99, TIM: 606
#, ErrorTime: 1706743154526, DTN: 1706769942627, LastBeatTime: 26773101, BPM: 4, TIM: 15000
#, ErrorTime: 1706743150778, DTN: 1706769942629, LastBeatTime: 26788101, BPM: 16, TIM: 3750
#, ErrorTime: 1706743150091, DTN: 1706769942631, LastBeatTime: 26791851, BPM: 87, TIM: 689
#, ErrorTime: 1706743149093, DTN: 1706769942633, LastBeatTime: 26792540, BPM: 60, TIM: 1000
#, ErrorTime: 1706743147331, DTN: 1706769942635, LastBeatTime: 26793540, BPM: 34, TIM: 1764
#, ErrorTime: 1706743140667, DTN: 1706769942637, LastBeatTime: 26795304, BPM: 9, TIM: 6666
#, ErrorTime: 1706743134669, DTN: 1706769942639, LastBeatTime: 26801970, BPM: 10, TIM: 6000
#, ErrorTime: 1706743133719, DTN: 1706769942641, LastBeatTime: 26807970, BPM: 63, TIM: 952
#, ErrorTime: 1706743125150, DTN: 1706769942643, LastBeatTime: 26808922, BPM: 7, TIM: 8571
#, ErrorTime: 1706743124546, DTN: 1706769942645, LastBeatTime: 26817493, BPM: 99, TIM: 606
#, ErrorTime: 1706743123798, DTN: 1706769942647, LastBeatTime: 26818099, BPM: 80, TIM: 750
#, ErrorTime: 1706743119515, DTN: 1706769942649, LastBeatTime: 26818849, BPM: 14, TIM: 4285
#, ErrorTime: 1706743117117, DTN: 1706769942651, LastBeatTime: 26823134, BPM: 25, TIM: 2400
#, ErrorTime: 1706743113120, DTN: 1706769942654, LastBeatTime: 26825534, BPM: 15, TIM: 4000
#, ErrorTime: 1706743112032, DTN: 1706769942656, LastBeatTime: 26829534, BPM: 55, TIM: 1090
#, ErrorTime: 1706743111284, DTN: 1706769942658, LastBeatTime: 26830624, BPM: 80, TIM: 750
#, ErrorTime: 1706743110536, DTN: 1706769942660, LastBeatTime: 26831374, BPM: 80, TIM: 750
#, ErrorTime: 1706743101967, DTN: 1706769942662, LastBeatTime: 26832124, BPM: 7, TIM: 8571
#, ErrorTime: 1706743100793, DTN: 1706769942664, LastBeatTime: 26840695, BPM: 51, TIM: 1176
#, ErrorTime: 1706743098488, DTN: 1706769942666, LastBeatTime: 26841871, BPM: 26, TIM: 2307
#, ErrorTime: 1706743097239, DTN: 1706769942667, LastBeatTime: 26844178, BPM: 48, TIM: 1250
#, ErrorTime: 1706743094084, DTN: 1706769942669, LastBeatTime: 26845428, BPM: 19, TIM: 3157
#, ErrorTime: 1706743074086, DTN: 1706769942671, LastBeatTime: 26848585, BPM: 3, TIM: 20000
#, ErrorTime: 1706743073219, DTN: 1706769942673, LastBeatTime: 26868585, BPM: 69, TIM: 869
#, ErrorTime: 1706743072388, DTN: 1706769942675, LastBeatTime: 26869454, BPM: 72, TIM: 833
#, ErrorTime: 1706743071693, DTN: 1706769942677, LastBeatTime: 26870287, BPM: 86, TIM: 697
#, ErrorTime: 1706743070826, DTN: 1706769942679, LastBeatTime: 26870984, BPM: 69, TIM: 869
#, ErrorTime: 1706743070183, DTN: 1706769942681, LastBeatTime: 26871853, BPM: 93, TIM: 645
#, ErrorTime: 1706743069496, DTN: 1706769942683, LastBeatTime: 26872498, BPM: 87, TIM: 689
#, ErrorTime: 1706743064883, DTN: 1706769942685, LastBeatTime: 26873187, BPM: 13, TIM: 4615
#, ErrorTime: 1706743061552, DTN: 1706769942687, LastBeatTime: 26877802, BPM: 18, TIM: 3333
#, ErrorTime: 1706743060936, DTN: 1706769942689, LastBeatTime: 26881135, BPM: 97, TIM: 618
#, ErrorTime: 1706743058796, DTN: 1706769942691, LastBeatTime: 26881753, BPM: 28, TIM: 2142
#, ErrorTime: 1706743057598, DTN: 1706769942693, LastBeatTime: 26883895, BPM: 50, TIM: 1200
#, ErrorTime: 1706743056705, DTN: 1706769942695, LastBeatTime: 26885095, BPM: 67, TIM: 895
#, ErrorTime: 1706743055374, DTN: 1706769942697, LastBeatTime: 26885990, BPM: 45, TIM: 1333
#, ErrorTime: 1706743053838, DTN: 1706769942699, LastBeatTime: 26887323, BPM: 39, TIM: 1538
#, ErrorTime: 1706743052220, DTN: 1706769942702, LastBeatTime: 26888861, BPM: 37, TIM: 1621
#, ErrorTime: 1706743051541, DTN: 1706769942704, LastBeatTime: 26890482, BPM: 88, TIM: 681
#, ErrorTime: 1706743049143, DTN: 1706769942706, LastBeatTime: 26891163, BPM: 25, TIM: 2400
#, ErrorTime: 1706743045616, DTN: 1706769942708, LastBeatTime: 26893563, BPM: 17, TIM: 3529
#, ErrorTime: 1706743041868, DTN: 1706769942710, LastBeatTime: 26897092, BPM: 16, TIM: 3750
#, ErrorTime: 1706743041239, DTN: 1706769942712, LastBeatTime: 26900842, BPM: 95, TIM: 631
#, ErrorTime: 1706743039778, DTN: 1706769942714, LastBeatTime: 26901473, BPM: 41, TIM: 1463
#, ErrorTime: 1706743039162, DTN: 1706769942716, LastBeatTime: 26902936, BPM: 97, TIM: 618
#, ErrorTime: 1706743035831, DTN: 1706769942718, LastBeatTime: 26903554, BPM: 18, TIM: 3333
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I don't agree.

Yes if you set a fixed value
B4X:
RndSeed(36)

but No if the value of seed is different every time
B4X:
#If RELEASE
Log("== RELEASE ==")
#Else
Log("** DEBUG **")
#End If
'Dim Seed As Long = 36
Dim Seed As Long = DateTime.Now
Log($"Seed=${Seed}"$)
RndSeed(Seed)
For i = 0 To 9
    Log( Rnd(1, 101) )
Next
It doesn't matter whether I am compiling in Debug or Release.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Using RndSeed is a little different. Its main purpose is to obtain the same sequence of random values at each execution of the software; this is useful for debugging the project.
When your project is ready to publish, you delete RndSeed.
Okay I get what you mean now.

It is only required if we need a fix sequence of random numbers. Otherwise it does nothing.

edit: Unless it is for OCD like me šŸ˜…
 
Upvote 0

swabygw

Active Member
Licensed User
Longtime User
I tried your code and seems fine to me. I get all kind of values for BPM:

B4X:
#, ErrorTime: 1706743178712, DTN: 1706769942615, LastBeatTime: 26763124, BPM: 77, TIM: 779
#, ErrorTime: 1706743177714, DTN: 1706769942617, LastBeatTime: 26763903, BPM: 60, TIM: 1000
#, ErrorTime: 1706743174859, DTN: 1706769942619, LastBeatTime: 26764903, BPM: 21, TIM: 2857
#, ErrorTime: 1706743171704, DTN: 1706769942621, LastBeatTime: 26767760, BPM: 19, TIM: 3157
#, ErrorTime: 1706743170128, DTN: 1706769942623, LastBeatTime: 26770917, BPM: 38, TIM: 1578
#, ErrorTime: 1706743169524, DTN: 1706769942625, LastBeatTime: 26772495, BPM: 99, TIM: 606
#, ErrorTime: 1706743154526, DTN: 1706769942627, LastBeatTime: 26773101, BPM: 4, TIM: 15000
#, ErrorTime: 1706743150778, DTN: 1706769942629, LastBeatTime: 26788101, BPM: 16, TIM: 3750
#, ErrorTime: 1706743150091, DTN: 1706769942631, LastBeatTime: 26791851, BPM: 87, TIM: 689
#, ErrorTime: 1706743149093, DTN: 1706769942633, LastBeatTime: 26792540, BPM: 60, TIM: 1000
#, ErrorTime: 1706743147331, DTN: 1706769942635, LastBeatTime: 26793540, BPM: 34, TIM: 1764
#, ErrorTime: 1706743140667, DTN: 1706769942637, LastBeatTime: 26795304, BPM: 9, TIM: 6666
#, ErrorTime: 1706743134669, DTN: 1706769942639, LastBeatTime: 26801970, BPM: 10, TIM: 6000
#, ErrorTime: 1706743133719, DTN: 1706769942641, LastBeatTime: 26807970, BPM: 63, TIM: 952
#, ErrorTime: 1706743125150, DTN: 1706769942643, LastBeatTime: 26808922, BPM: 7, TIM: 8571
#, ErrorTime: 1706743124546, DTN: 1706769942645, LastBeatTime: 26817493, BPM: 99, TIM: 606
#, ErrorTime: 1706743123798, DTN: 1706769942647, LastBeatTime: 26818099, BPM: 80, TIM: 750
#, ErrorTime: 1706743119515, DTN: 1706769942649, LastBeatTime: 26818849, BPM: 14, TIM: 4285
#, ErrorTime: 1706743117117, DTN: 1706769942651, LastBeatTime: 26823134, BPM: 25, TIM: 2400
#, ErrorTime: 1706743113120, DTN: 1706769942654, LastBeatTime: 26825534, BPM: 15, TIM: 4000
#, ErrorTime: 1706743112032, DTN: 1706769942656, LastBeatTime: 26829534, BPM: 55, TIM: 1090
#, ErrorTime: 1706743111284, DTN: 1706769942658, LastBeatTime: 26830624, BPM: 80, TIM: 750
#, ErrorTime: 1706743110536, DTN: 1706769942660, LastBeatTime: 26831374, BPM: 80, TIM: 750
#, ErrorTime: 1706743101967, DTN: 1706769942662, LastBeatTime: 26832124, BPM: 7, TIM: 8571
#, ErrorTime: 1706743100793, DTN: 1706769942664, LastBeatTime: 26840695, BPM: 51, TIM: 1176
#, ErrorTime: 1706743098488, DTN: 1706769942666, LastBeatTime: 26841871, BPM: 26, TIM: 2307
#, ErrorTime: 1706743097239, DTN: 1706769942667, LastBeatTime: 26844178, BPM: 48, TIM: 1250
#, ErrorTime: 1706743094084, DTN: 1706769942669, LastBeatTime: 26845428, BPM: 19, TIM: 3157
#, ErrorTime: 1706743074086, DTN: 1706769942671, LastBeatTime: 26848585, BPM: 3, TIM: 20000
#, ErrorTime: 1706743073219, DTN: 1706769942673, LastBeatTime: 26868585, BPM: 69, TIM: 869
#, ErrorTime: 1706743072388, DTN: 1706769942675, LastBeatTime: 26869454, BPM: 72, TIM: 833
#, ErrorTime: 1706743071693, DTN: 1706769942677, LastBeatTime: 26870287, BPM: 86, TIM: 697
#, ErrorTime: 1706743070826, DTN: 1706769942679, LastBeatTime: 26870984, BPM: 69, TIM: 869
#, ErrorTime: 1706743070183, DTN: 1706769942681, LastBeatTime: 26871853, BPM: 93, TIM: 645
#, ErrorTime: 1706743069496, DTN: 1706769942683, LastBeatTime: 26872498, BPM: 87, TIM: 689
#, ErrorTime: 1706743064883, DTN: 1706769942685, LastBeatTime: 26873187, BPM: 13, TIM: 4615
#, ErrorTime: 1706743061552, DTN: 1706769942687, LastBeatTime: 26877802, BPM: 18, TIM: 3333
#, ErrorTime: 1706743060936, DTN: 1706769942689, LastBeatTime: 26881135, BPM: 97, TIM: 618
#, ErrorTime: 1706743058796, DTN: 1706769942691, LastBeatTime: 26881753, BPM: 28, TIM: 2142
#, ErrorTime: 1706743057598, DTN: 1706769942693, LastBeatTime: 26883895, BPM: 50, TIM: 1200
#, ErrorTime: 1706743056705, DTN: 1706769942695, LastBeatTime: 26885095, BPM: 67, TIM: 895
#, ErrorTime: 1706743055374, DTN: 1706769942697, LastBeatTime: 26885990, BPM: 45, TIM: 1333
#, ErrorTime: 1706743053838, DTN: 1706769942699, LastBeatTime: 26887323, BPM: 39, TIM: 1538
#, ErrorTime: 1706743052220, DTN: 1706769942702, LastBeatTime: 26888861, BPM: 37, TIM: 1621
#, ErrorTime: 1706743051541, DTN: 1706769942704, LastBeatTime: 26890482, BPM: 88, TIM: 681
#, ErrorTime: 1706743049143, DTN: 1706769942706, LastBeatTime: 26891163, BPM: 25, TIM: 2400
#, ErrorTime: 1706743045616, DTN: 1706769942708, LastBeatTime: 26893563, BPM: 17, TIM: 3529
#, ErrorTime: 1706743041868, DTN: 1706769942710, LastBeatTime: 26897092, BPM: 16, TIM: 3750
#, ErrorTime: 1706743041239, DTN: 1706769942712, LastBeatTime: 26900842, BPM: 95, TIM: 631
#, ErrorTime: 1706743039778, DTN: 1706769942714, LastBeatTime: 26901473, BPM: 41, TIM: 1463
#, ErrorTime: 1706743039162, DTN: 1706769942716, LastBeatTime: 26902936, BPM: 97, TIM: 618
#, ErrorTime: 1706743035831, DTN: 1706769942718, LastBeatTime: 26903554, BPM: 18, TIM: 3333

Strange. Here is an example of my equivalent output:

#9, ErrorTime: 33, DTN: 1706769463271, LastBeatTime: 1706769462479, BPM: 79, TIM: 759
#10, ErrorTime: -21, DTN: 1706769464062, LastBeatTime: 1706769463238, BPM: 71, TIM: 845
#11, ErrorTime: 161, DTN: 1706769465139, LastBeatTime: 1706769464083, BPM: 67, TIM: 895
#12, ErrorTime: 88, DTN: 1706769465876, LastBeatTime: 1706769464978, BPM: 74, TIM: 810
#13, ErrorTime: 48, DTN: 1706769466595, LastBeatTime: 1706769465788, BPM: 79, TIM: 759
#14, ErrorTime: 126, DTN: 1706769467442, LastBeatTime: 1706769466547, BPM: 78, TIM: 769
#15, ErrorTime: 0, DTN: 1706769468105, LastBeatTime: 1706769467316, BPM: 76, TIM: 789
#16, ErrorTime: 22, DTN: 1706769468906, LastBeatTime: 1706769468105, BPM: 77, TIM: 779
#17, ErrorTime: 63, DTN: 1706769469757, LastBeatTime: 1706769468884, BPM: 74, TIM: 810
#18, ErrorTime: 35, DTN: 1706769470508, LastBeatTime: 1706769469694, BPM: 77, TIM: 779
#19, ErrorTime: -5, DTN: 1706769471268, LastBeatTime: 1706769470473, BPM: 75, TIM: 800
#20, ErrorTime: 40, DTN: 1706769472102, LastBeatTime: 1706769471273, BPM: 76, TIM: 789
#21, ErrorTime: 25, DTN: 1706769472837, LastBeatTime: 1706769472062, BPM: 80, TIM: 750
#22, ErrorTime: 40, DTN: 1706769473602, LastBeatTime: 1706769472812, BPM: 80, TIM: 750
#23, ErrorTime: -8, DTN: 1706769474343, LastBeatTime: 1706769473562, BPM: 76, TIM: 789
#24, ErrorTime: 66, DTN: 1706769475227, LastBeatTime: 1706769474351, BPM: 74, TIM: 810
#25, ErrorTime: 70, DTN: 1706769476010, LastBeatTime: 1706769475161, BPM: 77, TIM: 779
#26, ErrorTime: -22, DTN: 1706769476718, LastBeatTime: 1706769475940, BPM: 75, TIM: 800
#27, ErrorTime: 9, DTN: 1706769477499, LastBeatTime: 1706769476740, BPM: 80, TIM: 750
#28, ErrorTime: 28, DTN: 1706769478287, LastBeatTime: 1706769477490, BPM: 78, TIM: 769

The random number displayed in the Log on line 34 of the code shows random numbers, indeed, but the BPM seems to always be selecting the higher values. Could it be the timing of the loop condition on line 11 ("If DTN >= ((LastBeatTime - ERROR_ADJUSTMENT) + TIM) Then")? I was thinking that, maybe, because the GetBPM is before the looping condition, it changes the threshold needed to enter the loop, as a result (i.e., the TIM variable becomes a higher threshold)...not sure. Here's another output that demonstrates the strange behavior. It's a bit long but shows the random numbers, indeed, being generated but, coincidentally or not, the higher number just happens to be at the time of the entering of the loop:

BPM_Out: 54, DTN: 1706805254975
BPM_Out: 25, DTN: 1706805254996
BPM_Out: 89, DTN: 1706805255019
BPM_Out: 50, DTN: 1706805255040
BPM_Out: 10, DTN: 1706805255059
BPM_Out: 83, DTN: 1706805255082
BPM_Out: 32, DTN: 1706805255106
BPM_Out: 55, DTN: 1706805255128
BPM_Out: 83, DTN: 1706805255150
BPM_Out: 69, DTN: 1706805255171
BPM_Out: 27, DTN: 1706805255191
BPM_Out: 10, DTN: 1706805255210
BPM_Out: 100, DTN: 1706805255231
BPM_Out: 89, DTN: 1706805255253
BPM_Out: 73, DTN: 1706805255279
BPM_Out: 40, DTN: 1706805255307
BPM_Out: 50, DTN: 1706805255324
BPM_Out: 88, DTN: 1706805255344
BPM_Out: 13, DTN: 1706805255367
BPM_Out: 48, DTN: 1706805255390
BPM_Out: 78, DTN: 1706805255428
BPM_Out: 30, DTN: 1706805255446
BPM_Out: 95, DTN: 1706805255464
BPM_Out: 48, DTN: 1706805255483
BPM_Out: 54, DTN: 1706805255506
BPM_Out: 40, DTN: 1706805255528
BPM_Out: 44, DTN: 1706805255548
BPM_Out: 85, DTN: 1706805255568
BPM_Out: 77, DTN: 1706805255586
BPM_Out: 15, DTN: 1706805255604
BPM_Out: 87, DTN: 1706805255622
#0, ErrorTime: 43, DTN: 1706805255622, LastBeatTime: 1706805254890, BPM: 87, TIM: 689
BPM_Out: 19, DTN: 1706805255645
BPM_Out: 84, DTN: 1706805255669
BPM_Out: 42, DTN: 1706805255689
BPM_Out: 3, DTN: 1706805255712
BPM_Out: 68, DTN: 1706805255733
BPM_Out: 100, DTN: 1706805255750
BPM_Out: 30, DTN: 1706805255772
BPM_Out: 90, DTN: 1706805255793
BPM_Out: 12, DTN: 1706805255812
BPM_Out: 47, DTN: 1706805255830
BPM_Out: 98, DTN: 1706805255846
BPM_Out: 66, DTN: 1706805255864
BPM_Out: 47, DTN: 1706805255882
BPM_Out: 19, DTN: 1706805255906
BPM_Out: 61, DTN: 1706805255929
BPM_Out: 28, DTN: 1706805255949
BPM_Out: 58, DTN: 1706805255967
BPM_Out: 90, DTN: 1706805255990
BPM_Out: 26, DTN: 1706805256016
BPM_Out: 88, DTN: 1706805256037
BPM_Out: 88, DTN: 1706805256058
BPM_Out: 64, DTN: 1706805256080
BPM_Out: 83, DTN: 1706805256106
BPM_Out: 49, DTN: 1706805256122
BPM_Out: 52, DTN: 1706805256141
BPM_Out: 19, DTN: 1706805256156
BPM_Out: 39, DTN: 1706805256172
BPM_Out: 70, DTN: 1706805256190
BPM_Out: 4, DTN: 1706805256210
BPM_Out: 54, DTN: 1706805256230
BPM_Out: 46, DTN: 1706805256249
BPM_Out: 28, DTN: 1706805256268
BPM_Out: 26, DTN: 1706805256304
BPM_Out: 68, DTN: 1706805256326
BPM_Out: 28, DTN: 1706805256350
BPM_Out: 71, DTN: 1706805256370
BPM_Out: 47, DTN: 1706805256394
BPM_Out: 79, DTN: 1706805256415
#0, ErrorTime: 77, DTN: 1706805256415, LastBeatTime: 1706805255579, BPM: 79, TIM: 759
BPM_Out: 81, DTN: 1706805256434
BPM_Out: 16, DTN: 1706805256453
BPM_Out: 16, DTN: 1706805256469
BPM_Out: 25, DTN: 1706805256490
BPM_Out: 72, DTN: 1706805256513
BPM_Out: 81, DTN: 1706805256530
BPM_Out: 45, DTN: 1706805256546
BPM_Out: 99, DTN: 1706805256565
BPM_Out: 67, DTN: 1706805256585
BPM_Out: 1, DTN: 1706805256607
BPM_Out: 18, DTN: 1706805256631
BPM_Out: 66, DTN: 1706805256652
BPM_Out: 79, DTN: 1706805256675
BPM_Out: 34, DTN: 1706805256697
BPM_Out: 61, DTN: 1706805256716
BPM_Out: 32, DTN: 1706805256737
BPM_Out: 90, DTN: 1706805256760
BPM_Out: 21, DTN: 1706805256784
BPM_Out: 50, DTN: 1706805256810
BPM_Out: 40, DTN: 1706805256833
BPM_Out: 81, DTN: 1706805256855
BPM_Out: 65, DTN: 1706805256874
BPM_Out: 78, DTN: 1706805256898
BPM_Out: 25, DTN: 1706805257132
BPM_Out: 93, DTN: 1706805257155
#0, ErrorTime: 172, DTN: 1706805257155, LastBeatTime: 1706805256338, BPM: 93, TIM: 645
BPM_Out: 61, DTN: 1706805257176
BPM_Out: 79, DTN: 1706805257198
BPM_Out: 5, DTN: 1706805257216
BPM_Out: 86, DTN: 1706805257232
BPM_Out: 20, DTN: 1706805257252
BPM_Out: 9, DTN: 1706805257273
BPM_Out: 77, DTN: 1706805257298
BPM_Out: 6, DTN: 1706805257319
BPM_Out: 67, DTN: 1706805257337
BPM_Out: 69, DTN: 1706805257355
BPM_Out: 62, DTN: 1706805257375
BPM_Out: 87, DTN: 1706805257396
BPM_Out: 14, DTN: 1706805257420
BPM_Out: 71, DTN: 1706805257445
BPM_Out: 20, DTN: 1706805257471
BPM_Out: 44, DTN: 1706805257489
BPM_Out: 3, DTN: 1706805257512
BPM_Out: 94, DTN: 1706805257532
BPM_Out: 62, DTN: 1706805257554
BPM_Out: 7, DTN: 1706805257576
BPM_Out: 16, DTN: 1706805257599
BPM_Out: 89, DTN: 1706805257621
BPM_Out: 82, DTN: 1706805257639
BPM_Out: 25, DTN: 1706805257655
BPM_Out: 40, DTN: 1706805257674
BPM_Out: 98, DTN: 1706805257692
#0, ErrorTime: 97, DTN: 1706805257692, LastBeatTime: 1706805256983, BPM: 98, TIM: 612
BPM_Out: 29, DTN: 1706805257712
BPM_Out: 3, DTN: 1706805257734
BPM_Out: 90, DTN: 1706805257751
BPM_Out: 2, DTN: 1706805257769
BPM_Out: 56, DTN: 1706805257786
BPM_Out: 80, DTN: 1706805257808
BPM_Out: 21, DTN: 1706805257831
BPM_Out: 52, DTN: 1706805257857
BPM_Out: 28, DTN: 1706805257879
BPM_Out: 24, DTN: 1706805257900
BPM_Out: 20, DTN: 1706805257918
BPM_Out: 15, DTN: 1706805257935
BPM_Out: 44, DTN: 1706805257952
BPM_Out: 47, DTN: 1706805257974
BPM_Out: 26, DTN: 1706805257994
BPM_Out: 58, DTN: 1706805258014
BPM_Out: 33, DTN: 1706805258036
BPM_Out: 69, DTN: 1706805258052
BPM_Out: 98, DTN: 1706805258070
BPM_Out: 99, DTN: 1706805258089
BPM_Out: 70, DTN: 1706805258106
BPM_Out: 38, DTN: 1706805258124
BPM_Out: 6, DTN: 1706805258143
BPM_Out: 52, DTN: 1706805258160
BPM_Out: 10, DTN: 1706805258187
BPM_Out: 69, DTN: 1706805258208
BPM_Out: 14, DTN: 1706805258230
BPM_Out: 78, DTN: 1706805258251
BPM_Out: 3, DTN: 1706805258274
BPM_Out: 30, DTN: 1706805258301
BPM_Out: 65, DTN: 1706805258320
BPM_Out: 53, DTN: 1706805258339
BPM_Out: 92, DTN: 1706805258356
#0, ErrorTime: 109, DTN: 1706805258356, LastBeatTime: 1706805257595, BPM: 92, TIM: 652
BPM_Out: 45, DTN: 1706805258373
BPM_Out: 71, DTN: 1706805258390
BPM_Out: 62, DTN: 1706805258409
BPM_Out: 87, DTN: 1706805258429
BPM_Out: 67, DTN: 1706805258450
BPM_Out: 13, DTN: 1706805258471
BPM_Out: 100, DTN: 1706805258496
BPM_Out: 89, DTN: 1706805258513
BPM_Out: 11, DTN: 1706805258534
BPM_Out: 21, DTN: 1706805258555
BPM_Out: 100, DTN: 1706805258577
BPM_Out: 35, DTN: 1706805258597
BPM_Out: 58, DTN: 1706805258619
BPM_Out: 94, DTN: 1706805258642
BPM_Out: 96, DTN: 1706805258661
BPM_Out: 68, DTN: 1706805258682
BPM_Out: 51, DTN: 1706805258700
BPM_Out: 45, DTN: 1706805258721
BPM_Out: 95, DTN: 1706805258744
BPM_Out: 89, DTN: 1706805258765
BPM_Out: 99, DTN: 1706805258790
BPM_Out: 23, DTN: 1706805258813
BPM_Out: 19, DTN: 1706805258834
BPM_Out: 65, DTN: 1706805258859
BPM_Out: 70, DTN: 1706805258883
BPM_Out: 80, DTN: 1706805258907
BPM_Out: 9, DTN: 1706805258931
BPM_Out: 61, DTN: 1706805258955
BPM_Out: 67, DTN: 1706805258989
BPM_Out: 12, DTN: 1706805259006
BPM_Out: 14, DTN: 1706805259023
BPM_Out: 79, DTN: 1706805259041
#0, ErrorTime: 35, DTN: 1706805259041, LastBeatTime: 1706805258247, BPM: 79, TIM: 759
BPM_Out: 90, DTN: 1706805259062
BPM_Out: 37, DTN: 1706805259085
BPM_Out: 28, DTN: 1706805259115
BPM_Out: 4, DTN: 1706805259131
BPM_Out: 26, DTN: 1706805259150
BPM_Out: 8, DTN: 1706805259169
BPM_Out: 27, DTN: 1706805259190
BPM_Out: 27, DTN: 1706805259211
BPM_Out: 83, DTN: 1706805259234
BPM_Out: 97, DTN: 1706805259259
BPM_Out: 2, DTN: 1706805259282
BPM_Out: 35, DTN: 1706805259305
BPM_Out: 94, DTN: 1706805259327
BPM_Out: 10, DTN: 1706805259350
BPM_Out: 85, DTN: 1706805259368
BPM_Out: 96, DTN: 1706805259387
BPM_Out: 20, DTN: 1706805259407
BPM_Out: 3, DTN: 1706805259428
BPM_Out: 72, DTN: 1706805259452
BPM_Out: 97, DTN: 1706805259476
BPM_Out: 73, DTN: 1706805259494
BPM_Out: 13, DTN: 1706805259511
BPM_Out: 40, DTN: 1706805259527
BPM_Out: 83, DTN: 1706805259546
BPM_Out: 37, DTN: 1706805259565
BPM_Out: 90, DTN: 1706805259588
BPM_Out: 98, DTN: 1706805259611
BPM_Out: 6, DTN: 1706805259636
BPM_Out: 50, DTN: 1706805259661
BPM_Out: 26, DTN: 1706805259683
BPM_Out: 70, DTN: 1706805259704
BPM_Out: 15, DTN: 1706805259726
BPM_Out: 22, DTN: 1706805259748
BPM_Out: 40, DTN: 1706805259769
BPM_Out: 81, DTN: 1706805259792
#0, ErrorTime: 46, DTN: 1706805259792, LastBeatTime: 1706805259006, BPM: 81, TIM: 740
BPM_Out: 8, DTN: 1706805259810
BPM_Out: 53, DTN: 1706805259828
BPM_Out: 54, DTN: 1706805259845
BPM_Out: 86, DTN: 1706805259863
BPM_Out: 95, DTN: 1706805259881
BPM_Out: 99, DTN: 1706805259909
BPM_Out: 94, DTN: 1706805259930
BPM_Out: 67, DTN: 1706805259947
BPM_Out: 22, DTN: 1706805259963
BPM_Out: 74, DTN: 1706805259983
BPM_Out: 90, DTN: 1706805260005
BPM_Out: 83, DTN: 1706805260029
BPM_Out: 68, DTN: 1706805260052
BPM_Out: 22, DTN: 1706805260074
BPM_Out: 16, DTN: 1706805260092
BPM_Out: 2, DTN: 1706805260110
BPM_Out: 19, DTN: 1706805260127
BPM_Out: 74, DTN: 1706805260145
BPM_Out: 25, DTN: 1706805260163
BPM_Out: 41, DTN: 1706805260181
BPM_Out: 98, DTN: 1706805260200
BPM_Out: 71, DTN: 1706805260221
BPM_Out: 32, DTN: 1706805260242
BPM_Out: 69, DTN: 1706805260267
BPM_Out: 57, DTN: 1706805260291
BPM_Out: 45, DTN: 1706805260308
BPM_Out: 90, DTN: 1706805260328
BPM_Out: 87, DTN: 1706805260348
BPM_Out: 83, DTN: 1706805260368
BPM_Out: 26, DTN: 1706805260391
BPM_Out: 31, DTN: 1706805260411
BPM_Out: 68, DTN: 1706805260433
BPM_Out: 80, DTN: 1706805260455
BPM_Out: 100, DTN: 1706805260478
#0, ErrorTime: 132, DTN: 1706805260478, LastBeatTime: 1706805259746, BPM: 100, TIM: 600
BPM_Out: 16, DTN: 1706805260503
BPM_Out: 15, DTN: 1706805260520
BPM_Out: 61, DTN: 1706805260536
BPM_Out: 71, DTN: 1706805260555
BPM_Out: 33, DTN: 1706805260571
BPM_Out: 96, DTN: 1706805260589
BPM_Out: 54, DTN: 1706805260611
BPM_Out: 92, DTN: 1706805260632
BPM_Out: 95, DTN: 1706805260662
BPM_Out: 2, DTN: 1706805260684
BPM_Out: 46, DTN: 1706805260709
BPM_Out: 9, DTN: 1706805260728
BPM_Out: 12, DTN: 1706805260747
BPM_Out: 21, DTN: 1706805260767
BPM_Out: 90, DTN: 1706805260784
BPM_Out: 56, DTN: 1706805260801
BPM_Out: 58, DTN: 1706805260822
BPM_Out: 80, DTN: 1706805260845
BPM_Out: 100, DTN: 1706805260867
BPM_Out: 4, DTN: 1706805260891
BPM_Out: 97, DTN: 1706805260914
BPM_Out: 17, DTN: 1706805260937
BPM_Out: 86, DTN: 1706805260961
BPM_Out: 87, DTN: 1706805260984
BPM_Out: 8, DTN: 1706805261007
BPM_Out: 71, DTN: 1706805261030
BPM_Out: 68, DTN: 1706805261047
BPM_Out: 26, DTN: 1706805261064
BPM_Out: 48, DTN: 1706805261080
BPM_Out: 7, DTN: 1706805261099
BPM_Out: 3, DTN: 1706805261120
BPM_Out: 99, DTN: 1706805261144
#0, ErrorTime: 192, DTN: 1706805261144, LastBeatTime: 1706805260346, BPM: 99, TIM: 606
BPM_Out: 5, DTN: 1706805261167
BPM_Out: 64, DTN: 1706805261183
BPM_Out: 16, DTN: 1706805261200
BPM_Out: 33, DTN: 1706805261221
BPM_Out: 34, DTN: 1706805261240
BPM_Out: 89, DTN: 1706805261259
BPM_Out: 97, DTN: 1706805261280
BPM_Out: 31, DTN: 1706805261298
BPM_Out: 56, DTN: 1706805261319
BPM_Out: 52, DTN: 1706805261337
BPM_Out: 27, DTN: 1706805261356
BPM_Out: 94, DTN: 1706805261375
BPM_Out: 95, DTN: 1706805261392
BPM_Out: 72, DTN: 1706805261410
BPM_Out: 14, DTN: 1706805261430
BPM_Out: 53, DTN: 1706805261450
BPM_Out: 57, DTN: 1706805261469
BPM_Out: 12, DTN: 1706805261487
BPM_Out: 41, DTN: 1706805261507
BPM_Out: 19, DTN: 1706805261528
BPM_Out: 19, DTN: 1706805261548
BPM_Out: 95, DTN: 1706805261568
BPM_Out: 61, DTN: 1706805261588
BPM_Out: 68, DTN: 1706805261605
BPM_Out: 89, DTN: 1706805261625
BPM_Out: 13, DTN: 1706805261642
BPM_Out: 26, DTN: 1706805261664
BPM_Out: 45, DTN: 1706805261680
BPM_Out: 34, DTN: 1706805261697
BPM_Out: 36, DTN: 1706805261715
BPM_Out: 37, DTN: 1706805261732
BPM_Out: 38, DTN: 1706805261753
BPM_Out: 62, DTN: 1706805261769
BPM_Out: 93, DTN: 1706805261786
#0, ErrorTime: 189, DTN: 1706805261786, LastBeatTime: 1706805260952, BPM: 93, TIM: 645
BPM_Out: 25, DTN: 1706805261803
BPM_Out: 62, DTN: 1706805261824
BPM_Out: 25, DTN: 1706805261842
BPM_Out: 9, DTN: 1706805261861
BPM_Out: 93, DTN: 1706805261881
BPM_Out: 50, DTN: 1706805261903
BPM_Out: 98, DTN: 1706805261922
BPM_Out: 23, DTN: 1706805261940
BPM_Out: 87, DTN: 1706805261958
BPM_Out: 56, DTN: 1706805261977
BPM_Out: 52, DTN: 1706805261994
BPM_Out: 40, DTN: 1706805262014
BPM_Out: 95, DTN: 1706805262034
BPM_Out: 44, DTN: 1706805262055
BPM_Out: 96, DTN: 1706805262077
BPM_Out: 78, DTN: 1706805262098
BPM_Out: 75, DTN: 1706805262114
BPM_Out: 12, DTN: 1706805262133
BPM_Out: 36, DTN: 1706805262152
BPM_Out: 19, DTN: 1706805262172
BPM_Out: 19, DTN: 1706805262192
BPM_Out: 7, DTN: 1706805262212
BPM_Out: 48, DTN: 1706805262231
BPM_Out: 50, DTN: 1706805262248
BPM_Out: 40, DTN: 1706805262278
BPM_Out: 36, DTN: 1706805262298
BPM_Out: 20, DTN: 1706805262317
BPM_Out: 36, DTN: 1706805262337
BPM_Out: 46, DTN: 1706805262357
BPM_Out: 41, DTN: 1706805262377
BPM_Out: 66, DTN: 1706805262396
BPM_Out: 13, DTN: 1706805262414
BPM_Out: 16, DTN: 1706805262432
BPM_Out: 20, DTN: 1706805262453
BPM_Out: 78, DTN: 1706805262474
#0, ErrorTime: 108, DTN: 1706805262474, LastBeatTime: 1706805261597, BPM: 78, TIM: 769
BPM_Out: 2, DTN: 1706805262492
BPM_Out: 85, DTN: 1706805262512
BPM_Out: 67, DTN: 1706805262531
BPM_Out: 4, DTN: 1706805262552
BPM_Out: 62, DTN: 1706805262571
BPM_Out: 93, DTN: 1706805262591
BPM_Out: 8, DTN: 1706805262610
BPM_Out: 77, DTN: 1706805262631
BPM_Out: 53, DTN: 1706805262650
BPM_Out: 77, DTN: 1706805262666
BPM_Out: 12, DTN: 1706805262683
BPM_Out: 74, DTN: 1706805262699
BPM_Out: 57, DTN: 1706805262718
BPM_Out: 52, DTN: 1706805262737
BPM_Out: 92, DTN: 1706805262755
BPM_Out: 34, DTN: 1706805262775
BPM_Out: 49, DTN: 1706805262795
BPM_Out: 42, DTN: 1706805262816
BPM_Out: 70, DTN: 1706805262836
BPM_Out: 62, DTN: 1706805262855
BPM_Out: 69, DTN: 1706805262876
BPM_Out: 19, DTN: 1706805262900
BPM_Out: 86, DTN: 1706805262916
BPM_Out: 12, DTN: 1706805262933
BPM_Out: 51, DTN: 1706805262950
BPM_Out: 78, DTN: 1706805262968
BPM_Out: 97, DTN: 1706805262986
#0, ErrorTime: 2, DTN: 1706805262986, LastBeatTime: 1706805262366, BPM: 97, TIM: 618
BPM_Out: 50, DTN: 1706805263003
BPM_Out: 11, DTN: 1706805263022
BPM_Out: 56, DTN: 1706805263041
BPM_Out: 39, DTN: 1706805263063
BPM_Out: 41, DTN: 1706805263083
BPM_Out: 42, DTN: 1706805263101
BPM_Out: 65, DTN: 1706805263119
BPM_Out: 53, DTN: 1706805263139
BPM_Out: 38, DTN: 1706805263160
BPM_Out: 34, DTN: 1706805263180
BPM_Out: 50, DTN: 1706805263202
BPM_Out: 46, DTN: 1706805263222
BPM_Out: 4, DTN: 1706805263244
BPM_Out: 39, DTN: 1706805263263
BPM_Out: 12, DTN: 1706805263282
BPM_Out: 39, DTN: 1706805263303
BPM_Out: 44, DTN: 1706805263324
BPM_Out: 13, DTN: 1706805263346
BPM_Out: 92, DTN: 1706805263367
BPM_Out: 74, DTN: 1706805263389
BPM_Out: 91, DTN: 1706805263412
BPM_Out: 1, DTN: 1706805263431
BPM_Out: 36, DTN: 1706805263452
BPM_Out: 84, DTN: 1706805263475
BPM_Out: 90, DTN: 1706805263504
BPM_Out: 78, DTN: 1706805263527
BPM_Out: 83, DTN: 1706805263548
BPM_Out: 100, DTN: 1706805263570
BPM_Out: 20, DTN: 1706805263595
BPM_Out: 65, DTN: 1706805263615
BPM_Out: 93, DTN: 1706805263636
#0, ErrorTime: 7, DTN: 1706805263636, LastBeatTime: 1706805262984, BPM: 93, TIM: 645
BPM_Out: 48, DTN: 1706805263654
BPM_Out: 53, DTN: 1706805263672
BPM_Out: 14, DTN: 1706805263689
BPM_Out: 42, DTN: 1706805263706
BPM_Out: 54, DTN: 1706805263724
BPM_Out: 34, DTN: 1706805263739
BPM_Out: 66, DTN: 1706805263759
BPM_Out: 74, DTN: 1706805263775
BPM_Out: 36, DTN: 1706805263793
BPM_Out: 57, DTN: 1706805263815
BPM_Out: 85, DTN: 1706805263834
BPM_Out: 65, DTN: 1706805263854
BPM_Out: 21, DTN: 1706805263877
BPM_Out: 54, DTN: 1706805263900
BPM_Out: 65, DTN: 1706805263923
BPM_Out: 24, DTN: 1706805263943
BPM_Out: 56, DTN: 1706805263965
BPM_Out: 37, DTN: 1706805263988
BPM_Out: 34, DTN: 1706805264011
BPM_Out: 40, DTN: 1706805264034
BPM_Out: 7, DTN: 1706805264057
BPM_Out: 60, DTN: 1706805264074
BPM_Out: 26, DTN: 1706805264093
BPM_Out: 40, DTN: 1706805264111
BPM_Out: 93, DTN: 1706805264132
BPM_Out: 9, DTN: 1706805264150
BPM_Out: 73, DTN: 1706805264168
BPM_Out: 71, DTN: 1706805264186
BPM_Out: 49, DTN: 1706805264207
BPM_Out: 89, DTN: 1706805264222
BPM_Out: 37, DTN: 1706805264240
BPM_Out: 56, DTN: 1706805264260
BPM_Out: 63, DTN: 1706805264278
BPM_Out: 55, DTN: 1706805264302
BPM_Out: 75, DTN: 1706805264324
BPM_Out: 62, DTN: 1706805264345
BPM_Out: 18, DTN: 1706805264373
BPM_Out: 44, DTN: 1706805264396
BPM_Out: 6, DTN: 1706805264417
BPM_Out: 98, DTN: 1706805264439
#0, ErrorTime: 198, DTN: 1706805264439, LastBeatTime: 1706805263629, BPM: 98, TIM: 612
BPM_Out: 60, DTN: 1706805264457
BPM_Out: 68, DTN: 1706805264474
BPM_Out: 29, DTN: 1706805264492
BPM_Out: 43, DTN: 1706805264513
BPM_Out: 17, DTN: 1706805264536
BPM_Out: 4, DTN: 1706805264562
BPM_Out: 97, DTN: 1706805264580
BPM_Out: 2, DTN: 1706805264597
BPM_Out: 90, DTN: 1706805264616
BPM_Out: 94, DTN: 1706805264636
BPM_Out: 73, DTN: 1706805264656
BPM_Out: 92, DTN: 1706805264675
BPM_Out: 67, DTN: 1706805264696
BPM_Out: 65, DTN: 1706805264715
BPM_Out: 33, DTN: 1706805264735
BPM_Out: 2, DTN: 1706805264752
BPM_Out: 21, DTN: 1706805264769
BPM_Out: 90, DTN: 1706805264787
BPM_Out: 55, DTN: 1706805264807
BPM_Out: 64, DTN: 1706805264824
BPM_Out: 2, DTN: 1706805264842
BPM_Out: 36, DTN: 1706805264861
BPM_Out: 48, DTN: 1706805264884
BPM_Out: 62, DTN: 1706805264905
BPM_Out: 42, DTN: 1706805264927
BPM_Out: 17, DTN: 1706805264951
BPM_Out: 56, DTN: 1706805264992
BPM_Out: 51, DTN: 1706805265017
BPM_Out: 39, DTN: 1706805265042
BPM_Out: 89, DTN: 1706805265060
#0, ErrorTime: 145, DTN: 1706805265060, LastBeatTime: 1706805264241, BPM: 89, TIM: 674
BPM_Out: 45, DTN: 1706805265077
BPM_Out: 3, DTN: 1706805265094
BPM_Out: 5, DTN: 1706805265112
BPM_Out: 8, DTN: 1706805265131
BPM_Out: 93, DTN: 1706805265150
BPM_Out: 44, DTN: 1706805265192
BPM_Out: 99, DTN: 1706805265210
BPM_Out: 100, DTN: 1706805265230
BPM_Out: 57, DTN: 1706805265248
BPM_Out: 49, DTN: 1706805265267
BPM_Out: 67, DTN: 1706805265286
BPM_Out: 89, DTN: 1706805265304
SetSettings
** Activity (main) Pause, UserClosed = false **
Activity_Pause: false
SetSettings
No wakelock.
 
Last edited:
Upvote 0

swabygw

Active Member
Licensed User
Longtime User
I think I know the problem. It is the TIM variable. Because it's a division, the result can be very high (e.g., 60000 / 1 = 60000) which then makes the threshold to enter the loop too high when the BPM_Out is too low. So the BPM_Out must be high, to get a low TIM and enter the loop, thus, the higher BPM's process in the loop. The occurrence is still random, but the probability of entering the loop is significantly better with the higher BPM_Out and DTN which are both regenerated at each 1 tick. I think the solution is to get the random number once and wait until the DTN reaches it, at each round, instead of getting a new random number at each tick.
 
Upvote 0

swabygw

Active Member
Licensed User
Longtime User
That was it. I moved the TIM declaration to Globals, added "TIM = (60000 / GetBPM)" inside of the loop (instead of before the loop), and it worked better.
 
Upvote 0
Solution
Top