![]() |
Random Numbers
Anybody know how to Generate a random number?
If you check the pdfs that came with the compiler (CD:\mcc18\doc\MPLAB-C18-Libraries.pdf), there is a random number type thing, but I can't use it! Here: //Prototype int rand(void); //... /**************************************** * FUNCTION NAME: Random * PURPOSE: Returns a random char * CALLED FROM: Where ever * ARGUMENTS: none * RETURNS: unsigned char ****************************************/ unsigned char Random(void) { unsigned int rnd; rnd = Rand; rnd = rnd / RAND_MAX; return (unsigned char) (rnd & 0xFF); } The thing is, When I build, I get ...\user_routines.c:267:Error [1105] symbol 'Rand' has not been defined :confused: Help?!? |
Re: Random Numbers
You might want to try
Code:
rnd = rand(); |
Re: Random Numbers
Quote:
Code:
unsigned char Random(void)Other Half: ...\user_routines.c:289:Error [1131] type mismatch in assignment: Code:
void Default_Routine(void) |
Re: Random Numbers
Quote:
Quote:
Code:
pwm01=pwm03=Random(); |
Re: Random Numbers
Quote:
P.S.- if you dig hard enough, there is an option in the compiler to turn off case-sensitivity :D but that would be nonconforming :rolleyes: oh, well. |
Re: Random Numbers
I'm quite curious as to why you'd want to set your PWM outputs to a random value, though. Most of us prefer to remove random behavior from our robots ;)
|
Re: Random Numbers
If you are setting the values of the PWMs to a random number everytime the program loop is executed (every ~26ms) .... the motors probably wont do anything ... because theres no way they can change speeds that quickly.
|
Re: Random Numbers
Quote:
Quote:
The full code is: Code:
//... |
Re: Random Numbers
Code:
i_cCount = i_cCount; |
Re: Random Numbers
Quote:
|
| All times are GMT -5. The time now is 21:18. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi