Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

Random() function in Application Builder

Please login with a confirmed email address before reporting spam

Hi everyone. I develop the application for my graduation work in Comsol Multiphysics 5.4 and I have a problem. I need to initialize a random variable in the method, but I get an error "Random cannot be resolved to a type". How can I include the Random() function in my application?



2 Replies Last Post 30 janv. 2020, 11:11 UTC−5
Lars Dammann COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 5 years ago 30 janv. 2020, 11:06 UTC−5

Hi, I think you mean to use java.util.Random, is that right? The Application Builder does not manage imports automatically, so you will have to go to the preferences, in the tab "Methods" and activate the option "view all code". With that, you will find some extra code around each method, which shows that a COMSOL method is actually a Java class. At the top, there are imports for some classes by default. If you add java.util.Random to those imports, your code should work.

Alternatively you can refer to random by its full name "java.util.Random" instead of just "Random" everywhere you use it in the code, which also works.

Best wishes, Lars

Hi, I think you mean to use java.util.Random, is that right? The Application Builder does not manage imports automatically, so you will have to go to the preferences, in the tab "Methods" and activate the option "view all code". With that, you will find some extra code around each method, which shows that a COMSOL method is actually a Java class. At the top, there are imports for some classes by default. If you add java.util.Random to those imports, your code should work. Alternatively you can refer to random by its full name "java.util.Random" instead of just "Random" everywhere you use it in the code, which also works. Best wishes, Lars

Please login with a confirmed email address before reporting spam

Posted: 5 years ago 30 janv. 2020, 11:11 UTC−5

Heh, I found the solution of question :) It needed to click File -> Preferences -> Methods and check the flag in "View all code".

Heh, I found the solution of question :) It needed to click File -> Preferences -> Methods and check the flag in "View all code".

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.