random() function

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Jef_S
Flowcode v5 User
Posts: 5
Joined: Sun Oct 05, 2008 4:28 pm
Has thanked: 3 times
Been thanked: 1 time

random() function

Post 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

IVL
Posts: 17
Joined: Sat Sep 17, 2011 7:10 pm
Location: Belgium
Has thanked: 8 times
Been thanked: 5 times

Re: random() function

Post 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

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times

Re: random() function

Post 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
1 in 10 people understand binary, the other one doesn't !

Jef_S
Flowcode v5 User
Posts: 5
Joined: Sun Oct 05, 2008 4:28 pm
Has thanked: 3 times
Been thanked: 1 time

Re: random() function

Post 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

Jef_S
Flowcode v5 User
Posts: 5
Joined: Sun Oct 05, 2008 4:28 pm
Has thanked: 3 times
Been thanked: 1 time

Re: random() function

Post 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

Post Reply