randn() function generates the same sequence whenever I called it.
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
JangHo Cho
el 4 de Ag. de 2015
Comentada: JangHo Cho
el 5 de Ag. de 2015
Hello,
I used MATLAB coder for converting .m files to C files.
All the things are O.K. except randn() function. The problem is that auto-generated randn() function generates the same sequence of numbers all the time. So I changed it by using 'srand(time(NULL))'; and 'rand/(double)RAND_MAX';
Are there any settings for MATLAB coder to generated a different version of randn() function?
0 comentarios
Respuesta aceptada
Más respuestas (1)
Mike Hosea
el 4 de Ag. de 2015
Every time you start MATLAB it will deliver the same sequence if you don't provide your own seed first. Your generated code must match this behavior. Consequently, if that isn't what you want, you must use the rng function to seed the generator. There is an example here on MATLAB Answers somewhere that illustrates using the C time() function to with rng to seed the generator.
Ver también
Categorías
Más información sobre MATLAB Coder en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!