• Products
    • Isadora
    • Get It
    • ADD-ONS
    • IzzyCast
    • Get It
  • Forum
  • Help
  • Werkstatt
  • Newsletter
  • Impressum
  • Dsgvo
  • Press
  • Isadora
  • Get It
  • ADD-ONS
  • IzzyCast
  • Get It
  • Press
  • Dsgvo
  • Impressum

Navigation

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Tags

    [ANSWERED] chance.js Javascript Library

    How To... ?
    2
    3
    306
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      jtsteph last edited by Woland

      Hello,

      I am trying to use the chance.js javascript library. 


      https://chancejs.com/


      I have placed it in the Javascript Libraries folder and am testing using various iterations of this:

      include("chance.js");
      function main() {
          let a = chance.d20(); // Rolls a random 20-sided dice
          return a;
      }

      The javascript window does not report an error when closing, so i assume it is finding the library file. The monitor is telling me that chance is not defined.

      Am i doing this correctly? Is it that the chance.js library is incompatible with the isadora javascript engine?

      I would appreciate any input here.

      Thanks, J

      Isadora 4.0.2, W11 PRO 13700K (in a 4U case), 128GB RAM, 4 Lane M.2 Storage, RTX 3090, Ultraleap Motion 2, Behringer UMC404HD audio interface, Streamdeck XL, Streamdeck+, KorgNano Kontrol2.
      Website: http://justinstephenson.com

      bonemap 1 Reply Last reply Reply Quote 1
      • bonemap
        bonemap Izzy Guru @jtsteph last edited by

        @jtsteph

        I am interested in this to generate random numbers between ranges - but similarly was unable to get the chance.js library to take in Isadora.

        I did manage a solution that fits my purpose using 'math.random' function:

        // pseudo-random number generator between min and max range
        // iz_input 1 "trigger"
        // iz_input 2 "min"
        // iz_input 3 "max"
        // iz_output 1 "random"
        function main()
        {
        a = arguments[0];
        d = arguments[1];
        e = arguments[2];
        const minCeiled = Math.ceil(d);
        const maxFloored = Math.floor(e);
          {
        return [ Math.floor(Math.random() * (maxFloored - minCeiled + 1) + minCeiled)]; 
          // The maximum is inclusive and the minimum is inclusive
        }
        }
        

        best wishes

        Russell

        http://bonemap.com | Australia
        Izzy STD 4.2 | USB 3.6 | + Beta
        MBP 16” 2019 2.4 GHz Intel i9 64GB AMD Radeon Pro 5500 8 GB 4TB SSD | 14.5 Sonoma
        Mac Studio 2023 M2 Ultra 128GB | OSX 15.3 Sequoia
        A range of deployable older Macs

        1 Reply Last reply Reply Quote 1
        • J
          jtsteph last edited by

          @bonemap , Thanks for this. I was excited about the chance.js library because it offered random outputs to so many data types which would make things quite efficient here. I will try your method and am sure i could use it to work with other data types.

          Next up, I want to try papaparser.js for csv files. It looks promising.

          Isadora 4.0.2, W11 PRO 13700K (in a 4U case), 128GB RAM, 4 Lane M.2 Storage, RTX 3090, Ultraleap Motion 2, Behringer UMC404HD audio interface, Streamdeck XL, Streamdeck+, KorgNano Kontrol2.
          Website: http://justinstephenson.com

          1 Reply Last reply Reply Quote 0
          • First post
            Last post