Page 1 of 1

random() function

Posted: Mon May 21, 2012 8:40 pm
by Jef_S
Hi,
I'm trying to get a random number on a led array. In a calculation I'm using output = random(). This works fine in the simulation.
Boostc translates this into the operand rand() but when translating into asm the following errors appear:
error: invalid operand 'rand()'
error: failed to generate expressioninvalid operand 'rand()'
How can this be solved?
Thanks

Jef Schoonis

Re: random() function

Posted: Mon May 21, 2012 8:53 pm
by IVL
Hi,

I'm not sure about Flowcode, but most programming languages expect a "seed" value to be used.
So, try to use random(256) instead of random.
This would mean a random value between 0 and 256 -1 will be returned.


Regards,
Ivan

Re: random() function

Posted: Mon May 21, 2012 9:22 pm
by JohnCrow
Hi Jef

Have a look at this post.
It has a flowcode program with an example of using the random function.

http://www.matrixmultimedia.com/mmforum ... 967#p22091

Edit:
Dont forget to put the following statement in the supplimentary code box

#include <rand.h>

Otherwise the program wont work

Re: random() function

Posted: Tue May 22, 2012 7:16 pm
by Jef_S
IVL wrote:Hi,

I'm not sure about Flowcode, but most programming languages expect a "seed" value to be used.
So, try to use random(256) instead of random.
This would mean a random value between 0 and 256 -1 will be returned.


Regards,
Ivan
Hello Ivan,
Thanks for your input. I tried this but Flowcode does not accept anything between the brackets.
Regards

Jef

Re: random() function

Posted: Tue May 22, 2012 7:18 pm
by Jef_S
JohnCrow wrote:Hi Jef

Have a look at this post.
It has a flowcode program with an example of using the random function.

http://www.matrixmultimedia.com/mmforum ... 967#p22091

Edit:
Dont forget to put the following statement in the supplimentary code box

#include <rand.h>

Otherwise the program wont work

Thanks John,

This does the job for me.

Kind regards
Jef