I am trying to create hangman on the Casio calculator cg50, I have followed the starting tutorial on c and managed to create text on the screen, however I am stuck on how to generate random numbers... I have tried to use the rand() function but got this error
Code:
example.c:(.text.startup.main+0x6c): undefined reference to `_rand'
. Any help to generate random numbers will be greatly appreciated.
Currently, you need to use sys_rand(), rand() doesn't actually do everything.

I am currently making a PR to add rand() as an alias to sys_rand().
dr-carlos wrote:
Currently, you need to use sys_rand(), rand() doesn't actually do everything.

I am currently making a PR to add rand() as an alias to sys_rand().


The PR has just been merged, so if you update your libfxcg from github and then recompile, rand() should work!

Let me know if there are any problems.
Thanks for the quick reply, but how do I set the seed, as the output seems to be the same every time
I have figured it out if anyone else needs it, basically you use sys_srand(12) to set the seed to 12
And to get a different seed every time, just have a number in a txt file and increment it at every run and use that as the seed
Thank you very much dr-carlos Smile
MichaelY wrote:
Thank you very much dr-carlos Smile

You're welcome!

I'm very happy to (try) and answer any other questions.
After looking at some stack overflow pages, it seems like the seed is normally set using time... Is there a time function that can be used? as simply using time(NULL) isn't working
The clock() function in time.h should work.
It is just a wrapper for RTC_GetTicks(), which returns the number of ticks (1/128 second) since midnight.

If this is not random enough, you can read the Real-Time Clock article on WikiPrizm, which tells you how to get the internal date, month, year, etc..
Thank you very much dr-carlos, but do you know if there is a place where I can get all these information because it seems like most of the usual modules/pakages like stdlib are implemented a little differently... Like I said I can't thank you enough Smile
That's all good, I'm happy to help.

Unfortunately, there isn't any good documentation on the standard library for libfxcg.

You can look at the headers and source code itself (GitHub repo), or check WikiPrizm for syscalls - but that's about it.

You raise a good point about there being no documentation for this area.
If someone were to document it, what kind of information might you find useful?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement