- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
srand() does not work for microblaze
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-08-2008 06:55 AM
i'm using microblaze to generate random values, but it seemd that srand() does not work. no mater which value i give to srand(), rand() generate the same vetor of values.
What's the problem?
Re: srand() does not work for microblaze
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-12-2010 05:18 AM
Hi,
when the program is stored in on-chip BRAM, after configuration of the FPGA rand() returns always the same sequence. Calling srand() does not change this behavior. When the system is reset and not reprogrammed, srand() behaves as expected. Calling rand() once before srand() works for me. Side note: srand()/rand() requires about 256 Bytesof heap to work.
All tests using EDK 10.1 SP3, MicroBlaze 7.10.d
Broken:
int main()
{
srand(2);
for( int i = 0; i < 3; i++)
{
putnum(rand());print("\r\n");
}
return 0;
}
Output after programming:
00000000
5851f42d
40b18ccf
Output after system reset:
30a3e85a
29112571
56ba5fbd
Workaround:
int main()
{
rand();
srand(2);
for( int i = 0; i < 3; i++)
{
putnum(rand());print("\r\n");
}
return 0;
}
Output after programming:
30a3e85a
29112571
56ba5fbd
Best regards,
Andreas











