Page 1 of 1

Assign random character to text Actor

PostPosted: 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.

PostPosted: 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'

PostPosted: 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] );

Image

PostPosted: Wed Jul 06, 2005 12:47 am
by makslane
Use this:

char *s = "abcdefghijklmnopqrstuvwxyz1234567890";

sprintf(text, "%c", s[(int)rand(strlen(s) - 1)]);

PostPosted: Wed Jul 06, 2005 12:48 am
by makslane
Matrix :-) Tell me if I can put on site!

PostPosted: Wed Jul 06, 2005 1:12 am
by jazz_e_bob

PostPosted: Wed Jul 06, 2005 6:52 am
by ingsan
WOW :shock: CoOL 8)

PostPosted: Wed Jul 06, 2005 11:57 am
by makslane
Thank you!