Random seed LUA/JUCE question

Home Forums General Programming Random seed LUA/JUCE question

Tagged: ,

This topic contains 3 replies, has 3 voices, and was last updated by  theuriah 1 week, 2 days ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #116042

    m.tarenskeen
    Participant
    • Topics: 28
    • Replies: 108
    • Total: 136
    • ★★

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

    math.randomseed(os.time())

    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 1 week, 5 days ago by  m.tarenskeen.
    #116044
    Possemo
    Possemo
    Participant
    • Topics: 13
    • Replies: 585
    • Total: 598
    • ★★★

    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:
    math.randomseed(os.time()*os.clock())
    It seems that a big number makes a better seed.

    #116047

    m.tarenskeen
    Participant
    • Topics: 28
    • Replies: 108
    • Total: 136
    • ★★

    Thanks Possemo,

    That should help.
    I will try your suggestions.

    #116074

    theuriah
    Participant
    • Topics: 0
    • Replies: 1
    • Total: 1

    Hi!

    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)

You must be logged in to reply to this topic.

There is currently 0 users and 23 guests online
No users are currently active
Forum Statistics
Threads: 2,245, Posts: 15,811, Members: 56,130
Most users ever online was 12 on January 22, 2019 3:47 pm
Do NOT follow this link or you will be banned from the site!