- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
rand() function doesn't do anything on MicroBlaze ?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
08-19-2009 05:15 PM
I've been trying to use the random number generator in a C project created by Xilinx XPS SDK 10.1 sp3 but it doesn't output anything.
If i do a
int random = (int) rand();
printf("randomnumber %d", random);
only "randomnumber" is printed and no number follows it.
printf("RAND_MAX = %u\n", RAND_MAX);
returns 2147483647.
I have a system configured with a uartlite as the stdin and stdout, stdlib.h and stdio.h included. Stack and heap size is configured to be 0xEEE.
How do I get the random number generator to function? It's very important to my application, and I'm completely clueless =/ thanks!
Re: rand() function doesn't do anything on MicroBlaze ?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
08-20-2009 03:15 AM
Hello.
Have you initialised your random function before using it.
I think you should use SRAND(0) first before using
random = rand();
--
Unlimited in my Limits.
Re: rand() function doesn't do anything on MicroBlaze ?
[ Edited ]
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
08-20-2009 04:17 AM - edited 08-20-2009 04:18 AM
Hello.
I took a system of UART and microblaze simply.
Software code is mentioned below.
**************************************************
#include "stdio.h"
#include "stdlib.h"
#include "xuartlite_l.h"
main()
{
int random;
//srand(0);
while(1)
{
random=rand()%10 + 1;
XUartLite_SendByte (0x84000000, random);
xil_printf("\n\r");
}
}
**************************************************
The above code and system is working.
It will be display random numbers between 1 to 10.
Check it out.
Also i found out that srand(0) has nothing do with rand().
So you can ignore it.
--
Unlimited in my Limits.
Re: rand() function doesn't do anything on MicroBlaze ?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
08-20-2009 10:39 AM
I'm assuming 0x84000000 is the base address of the Uart?
If it is, my terminal is showing a blank screen. xil_printf is working, so it keeps scrolling, but everything else is blank. Could it be other peripherals (like DDR2) interfering with the rand()?
Re: rand() function doesn't do anything on MicroBlaze ?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
08-20-2009 11:19 AM
You stated that:
printf("randomnumber %d", random);
only "randomnumber" is printed and no number follows it.
That code sequence has nothing to do with rand() itself - you should consider rand as not working only if multiple calls to rand do not return random numbers. From the above code, it looks to me like you just cannot print out integers out on stdout. That probably means that you have insufficient stack/heap. Just try printing out any local integer variable, and see if it comes out.
Re: rand() function doesn't do anything on MicroBlaze ?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
08-21-2009 04:06 PM
Re: rand() function doesn't do anything on MicroBlaze ?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-12-2010 03:02 AM
Hi,
rand() seems to need some heap space. Having 256 Bytes heap space or more rand() works reliably. Sadly, this is not mentioned anywhere in the documents, at least not in oslib_rm.pdf as of EDK 10.1 SP3.
Best regards,
Andreas











