Hello all!
I am in the need of help in creating random decimal numbers in C.
The values are supposed to be in the intervall of -1.4 to 1.4.
Would anyone who knows how to solve this be so kind as to pose a code passage containing the solution?
Many, many thanks and kind regards!
|
|
0
|
|
|
|
Reply
|
Ansgar
|
10/16/2010 3:11:03 PM |
|
Well, sorry, but this is a Matlab forum and you might get better advice on a C forum! However, one possibility would be to use the rand() function, if its statistical properties are good enough for your application (you have to test). As far as I remember, it returns integers in the range 0 to RAND_MAX, so to get a float in the range 0 to 1 you just cast the result and divide by RAND_MAX.
|
|
0
|
|
|
|
Reply
|
David
|
10/16/2010 6:24:03 PM
|
|
Wel, sorry, but I am writing S-Functions in C which delivers way better performance than M-File S-Functions. Therefor this can be understood as a Matlab related problem. But thanks for the information.
|
|
0
|
|
|
|
Reply
|
Ansgar
|
10/16/2010 8:16:03 PM
|
|
Dear Ansgar,
there is an implementation of Marsaglia's KISS random number generator in the C-Mex function SHUFFLE published in the FEX.
Good luck, Jan
|
|
0
|
|
|
|
Reply
|
Jan
|
10/17/2010 7:58:03 PM
|
|