I have a class with a method which returns, let's say, an object of type X - should I use an association to class X? I think that I should not because associations should be used when we have an instance variable of the particular type. Please, clear my confusion.
The second question. I have a class with an instance reference to class java.util.Random (I use only nextDouble() method, but many times). I think that I should mark it as an association to class Random and I am going to write nextDouble() in the class rectangle only. Am I correct?
If object x comes from object y, then there is an association between the objects. In order to clearly describe this relationship in a Class diagram, you may use the symbol for Association. Note that in the UML, there are other types of relationships, e.g. Composition, Aggregation, etc.
In terms of the second question, you can certainly specify the method being used in a Class diagram, e.g. nextDouble(). This would be understandable. Moreover, in some Class diagrams you may chose not to include any methods and simply use the names of the Classes. In other Class diagrams, you might only specify the fields and not include the methods. It depends on the situtation and how "you" want to use the diagrams, who will read the diagrams, and other factors.