2

Hello,I need a function as random in C language. Maybe you will say that i can call C function, but the effect is not the same in visual c++ tool. So, I need your help. thanks.

Laughing
  • 33
  • 2
  • possible duplicate: http://stackoverflow.com/questions/36265293/assignment-problems-with-simple-random-number-generation-in-modelica – matth Apr 01 '16 at 07:34
  • Thanks, but i want it works like c: int res=random()%100; – Laughing Apr 11 '16 at 02:36

2 Answers2

3

See the Noise library:

https://github.com/DLR-SR/Noise

It has some models and functions to generate random numbers.

Adrian Pop
  • 4,034
  • 13
  • 16
1

If you are using Dymola, you can use the function rand():

model rand_model
  Real a(start=rand());
  Real b(start=rand());
equation 
  when (sample(1,1)) then
    a = rand();
    b = rand();
  end when;
end rand_model;

The function is not documented in the Dymola user manual and it is no part of the modelica standard. The output seems to be an integer between 0 and 32767, seed seems to be constant.

Perhaps the implementation is given in the moutil.c file which is shipped with Dymola. But i'm not sure.

Richard Erickson
  • 2,568
  • 8
  • 26
  • 39
Lukas Exel
  • 86
  • 5