Page 1 of 1
DND dice roller
Posted: Fri Nov 19, 2021 11:05 am
by BellDynJinn
Hi, i am programming a DND dice roller for a college project but can't seem to get the random number generator part, used to simulate a dice roll, to work. could someone take a look at what i have done so far and try to get it to work.
i will be working on this while i wait to see if anyone can help and if i can get it to work before someone can help me, ill edit this post below to show that i havew resolved it.
current state: seemingly resolved.
Re: DND dice roller
Posted: Fri Nov 19, 2021 12:55 pm
by medelec35
Hi, BellDynJinn.
Welcome to the forums.
You can use the Random() function within a calculation icon, no need for it to be contained within a C code block
For example, you can use the random in the following way:

- Random Number.png (6.37 KiB) Viewed 4604 times
The % means modulus.
Note the random values are pseudo which means they are is statistically random, but it is derived from a known starting point.
So every time power is applied, the same random numbers will be derived.
There is a way around that.
The stand function can be used.
What I do is Add an available ADC channel, and leave the pin floating.
Assing a variable e.g
.
Then use a c code block before the main loop with:
Re: DND dice roller
Posted: Sun Nov 21, 2021 7:08 pm
by BellDynJinn
its the Random function itself that isnt working, i cant get it to generate a number other than 0.
Re: DND dice roller
Posted: Sun Nov 21, 2021 7:20 pm
by medelec35
Have you tried what I have shown within the image?
That should give you a random number between the min and max values.
If you have and still not working, then post our updated flowchart, please.
Don't forget to enter
Code: Select all
RandNum = random () % (MaxNum - MinNum + 1) + MinNum
within a calculation icon:

- Calculation Icon.png (2.3 KiB) Viewed 4550 times
Re: DND dice roller
Posted: Wed Nov 24, 2021 1:54 pm
by BellDynJinn
when i have tried, in the past and just now, to do it through the calculation method(or the way you have suggested) it always has 0 as the result.
Re: DND dice roller
Posted: Wed Nov 24, 2021 1:55 pm
by BellDynJinn
heres the updated file
Re: DND dice roller
Posted: Wed Nov 24, 2021 2:53 pm
by medelec35
That is because you are calling a user macro (D4) and expecting a return value.
Within the call user macro, you must specify
The
means it's a local variable.
Just select the Locals icon and drag
or just type it in.
Your calculation should look like this:

- Use Return.png (41.34 KiB) Viewed 4508 times
Re: DND dice roller
Posted: Thu Nov 25, 2021 10:03 am
by BellDynJinn
ok i will try that later today when i have access to flowcode.
Re: DND dice roller
Posted: Fri Nov 26, 2021 10:47 am
by BellDynJinn
medelec35 wrote: ↑Wed Nov 24, 2021 2:53 pm
That is because you are calling a user macro (D4) and expecting a return value.
Within the call user macro, you must specify
The
means it's a local variable.
Just select the Locals icon and drag
or just type it in.
Your calculation should look like this:Use Return.png
that seems to be working now thank you
Re: DND dice roller
Posted: Sat Nov 27, 2021 4:19 pm
by medelec35
You're welcome.
Thanks for letting us know.