+4 votes
348 views
in Modeling by Fabian de Gasparo (28 points)

Hello,

I want to generate a random number at startup of the VHIL. For that I want a random seed. However I was not able to use srand(time(NULL)).

What is the alternative to #include <time.h> in the schematic editor?

How can I know thich libraries are already installed?

Then I also have a more genral questions to the c-functions. How to debug? "Exception occured: ... please make the needed correction..." is not helping.

Thanks in advance! The help is appriciated a lot.

Best,

Fabian

<!--StartFragment--><!--EndFragment-->

3 Answers

+1 vote
by Dusan Kostic (211 points)
selected by Dusan Kostic
 
Best answer

Hi Fabian,

You can check the C language libraries available in the C function component in the following FAQ article

For generated random numbers in signal processing I suggest you using Repeating Sequence Discrete component and defining "Vector of output values" property in the python code. Here is an example how you can create an list of 10,000 random numbers between 0 and 1:

import random
random_numbers = [random.random() for _ in range(10000)]

With an execution rate of 100e-6, this will generate 1s of random numbers, after which the signal will start repeating. I believe this could be a suitable alternative for generating random numbers in C code.

You can find the model illustrating this approach in the attachment.

python random generator.tse

0 votes
by Era Bajpai (314 points)

Dear Fabian,

You can use this link to understand which python libraries are currently installed and supported.

Regarding c-function block, could you maybe try to send a screenshot the error? In case there is a syntax issue in the code, try to use check syntax option available at the bottom of the c-function dialog box.

Hope this helps.

by Fabian de Gasparo (28 points)
Hello,
Unfortunately this was not my question. I am not talking about test IDE but about C functions.

Concerning the error that is not very usful I mean this:

-----------------------------------
Exception occurred: [13-Feb-2025 @ 11:33:09 AM]
-----------------------------------
2024.3
Please, make the needed corrections and restart the compilation.
Compilation process interrupted.
0 votes
by Ricardo Morim (150 points)
Hello Fabian,

In C function you can use rand() to get a random number.

W.r.t the error you are getting, it probably has to do with some syntax issue in your C code.

Try looking at the log files generated in Target Files folder.

Regards,

Ricardo
...