Assign random character to text Actor
Posted:
Tue Jul 05, 2005 4:03 am
by jazz_e_bob
How do I do this in C?
strcpy ( textActor.text, char$(random) );
Thanks in advance.
Posted:
Tue Jul 05, 2005 1:44 pm
by makslane
You can use this code:
sprintf(textActor.text, "%c", 'A'+(int)rand(25));
Where:
'A': is your initial letter
rand(23): will return a value between 0 and 25
So, you can get letters from 'A' to 'A'+25 = 'Z'
Posted:
Tue Jul 05, 2005 9:57 pm
by jazz_e_bob
Yep, that works. Thanks mate.
http://www.artsystems.com.au/game%20editor/ge%20matrix.zip
What if I have a string "abcdefghijklmnopqrstuvwxyz1234567890"
How do I pick out a single character from the string?
eg: strcpy ( textActor.text, [random character from string] );
Posted:
Wed Jul 06, 2005 12:47 am
by makslane
Use this:
char *s = "abcdefghijklmnopqrstuvwxyz1234567890";
sprintf(text, "%c", s[(int)rand(strlen(s) - 1)]);
Posted:
Wed Jul 06, 2005 12:48 am
by makslane
Matrix
Tell me if I can put on site!