code to generate random numbers

code to generate random numbers

gary_q2
Not applicable
436 Views
7 Replies
Message 1 of 8

code to generate random numbers

gary_q2
Not applicable

How do I generate random numbers and print that information in the output console that I write? I'm just using a source and sink I would appreciate a help

0 Likes
Accepted solutions (1)
437 Views
7 Replies
Replies (7)
Message 2 of 8

joerg_vogel_HsH
Mentor
Mentor

@Gary Q2, duniform( number left side, right side of the interval, number of the. random number stream) if you are looking for discrete values.

uniform( left side or minimum value, right side or maximum value, random number stream) for a continuous floating number interval as double.

double numberRandom = uniform(0,1,0); // random interval ]0..1[
print(numberRandom); // print random number
Message 3 of 8

jeff_nordgren
Not applicable
Accepted solution

@Gary Q2

A random whole number a random decimal number, what? If you are wanting a random whole number between 1 and 100, you would write something like this:

print(duniform(1, 100)); //Prints the number to the output console

Is this what you are looking for?

Message 4 of 8

joerg_vogel_HsH
Mentor
Mentor
print( value or string, value or string, value or string,..) 

is a new command to write in the output console

Message 5 of 8

gary_q2
Not applicable

Generate numbers from 0 to 1, I do not print the numbers in the output console: the code you used was in the triggers on exit tab double ran = randnext (1); pf (ran); pt (""); What error is there ?? @Jeff Nordgren

0 Likes
Message 6 of 8

Ben_WilsonADSK
Community Manager
Community Manager

@Gary Q2,

uniform(0,1) will give a real number between 0 and 1.

0 Likes
Message 7 of 8

jeff_nordgren
Not applicable

@Gary Q2,

Not exactly sure what you are after. The answers that @Ben Wilson and @Jörg Vogel gave seem to answer your question. If they don't answer your question, can you explain why they don't?

Thanks.

0 Likes
Message 8 of 8

gary_q2
Not applicable
thank you very much for the help, I found the expected result
Thank you
0 Likes