A question was posed in Friday's class regarding the rand() function. The person wanted to know how to make their robot move for a random range of time; specifically between 0 and 4 seconds. I used the help menu in ROBOTC to show the rand() function, but I didn't think I did a very good job answering the question. With that in mind, I wanted to share the following code. The code contains comments that hopefully explains everything. If there are any other questions or comments, please feel free to chime in. Thanks,

There are many, many other parameters that can be used with the rand() function (for instance, to tweak the seed values used for the random number generation), but for basic random number generation, the rand() function will suffice.*/

long rTime = 0;//Created a global variable. The data type is long in order to get a bigger range of valuestask main(){

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum