Photonics

Photonics

Topics related to Lumerical and more.

How to generate a random integer within a specified range?

    • 10172100207
      Subscriber

      Xmin = [80,300,30,160,10]; # D,P,H,G min

      Xmin = [100,400,50,20,10];

      Xmax = [160,700,200,320,200]; 

      p1(i,j) = Xmin(j) + rand*(Xmax(j) - Xmin(j));

      But I want the rand(between 0 and 1)*(Xmax(j) - Xmin(j)) to be an int number, not float. 

    • Kirill
      Ansys Employee

      Hello Subscriber,

      1.       Consider using the following functions, which take a floating-point argument and return an integer: ceil (rounds up), floor (rounds down), and round (rounds to the nearest integer).

      2.       The rand function itself can also return an integer directly when used with 3 arguments. Please check the linked documentation for details.

       

      Additionally, you may find it helpful to review the Ansys Optics Scripting Language section, as well as the Ansys Lumerical Scripting Course.

       

      Best regards,

      Kirill

Viewing 1 reply thread
  • You must be logged in to reply to this topic.