Assign random character to text Actor

Game Editor comments and discussion.

Assign random character to text Actor

Postby jazz_e_bob » Tue Jul 05, 2005 4:03 am

How do I do this in C?

strcpy ( textActor.text, char$(random) );

Thanks in advance.
Controlling complexity is the essence of computer programming.
User avatar
jazz_e_bob
 
Posts: 742
Joined: Tue Jul 01, 2003 9:38 pm
Location: Bloke from Cockatoo Creek Australia
Score: 14 Give a positive score

Postby makslane » Tue Jul 05, 2005 1:44 pm

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'
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby jazz_e_bob » Tue Jul 05, 2005 9:57 pm

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
Controlling complexity is the essence of computer programming.
User avatar
jazz_e_bob
 
Posts: 742
Joined: Tue Jul 01, 2003 9:38 pm
Location: Bloke from Cockatoo Creek Australia
Score: 14 Give a positive score

Postby makslane » Wed Jul 06, 2005 12:47 am

Use this:

char *s = "abcdefghijklmnopqrstuvwxyz1234567890";

sprintf(text, "%c", s[(int)rand(strlen(s) - 1)]);
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby makslane » Wed Jul 06, 2005 12:48 am

Matrix :-) Tell me if I can put on site!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby jazz_e_bob » Wed Jul 06, 2005 1:12 am

Controlling complexity is the essence of computer programming.
User avatar
jazz_e_bob
 
Posts: 742
Joined: Tue Jul 01, 2003 9:38 pm
Location: Bloke from Cockatoo Creek Australia
Score: 14 Give a positive score

Postby ingsan » Wed Jul 06, 2005 6:52 am

WOW :shock: CoOL 8)
User avatar
ingsan
 
Posts: 580
Joined: Mon Nov 17, 2003 4:02 pm
Location: Maurician LADY in FRANCE
Score: 6 Give a positive score

Postby makslane » Wed Jul 06, 2005 11:57 am

Thank you!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest