Random seed LUA/JUCE question

Home Forums General Programming Random seed LUA/JUCE question

Tagged: ,

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #116042
    • Topics: 30
    • Replies: 113
    • Total: 143
    • ★★

    In many of my panels I use some LUA code to initialize a randomizer function like this


    before I make use of math.random(x,y)
    But a Mac user reported to me it doesn’t work on his version of Ctrlr.
    Apparently os.time() isn’t supported on his system. Now I am looking for an alternative that has a better chance to work on all platforms, and on most versions of Ctrlr. (My main platform is Linux, I can test on Windows, but don’t own any Apple hardware)

    Maybe Time from JUCE can be used? If so, how? I am having problems finding the right LUA syntax and usage to call and use available JUCE classes. In general I have problems understanding and translating JUCE’s online documentation in LUA syntax that I can use inside Ctrlr. And not all existing JUCE classes are available inside Ctrlr.

    I could use some hints and help …

    • This topic was modified 2 years, 8 months ago by m.tarenskeen.
    • Topics: 14
    • Replies: 638
    • Total: 652
    • ★★★

    Maybe this guy has an ancient MacOs and/or he is using an old build of Ctrlr. os.time() does work on actual MacOs’es with the actual Ctrlr Mac-build. As an alternative you could use math.randomseed(Time.getMillisecondCounterHiRes())
    In theory the hires counter should give a better seed but my experience is that it just gives slightly different results. Sometimes better, sometimes worse than my other method:
    It seems that a big number makes a better seed.

    • Topics: 30
    • Replies: 113
    • Total: 143
    • ★★

    Thanks Possemo,

    That should help.
    I will try your suggestions.

    • Topics: 0
    • Replies: 1
    • Total: 1


    I’m the Mac user in question. In the interest of complete info being in the thread here…

    I’m running Mojave 10.14.6, and CTRLR.v.5.2.100. I’m on this version after having the “resource bug” problem of not being able to use/find image files doing an update on the PSS-480 Panel.

    I changed the line to: math.randomseed(Time.getMillisecondCounterHiRes())
    …and it worked like a charm!

    Thanks all!

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Programming’ is closed to new topics and replies.
There is currently 0 users and 27 guests online
No users are currently active
Forum Statistics
Threads: 2,495, Posts: 17,374, Members: 77,605
Most users ever online was 12 on January 22, 2019 3:47 pm