RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Random Letters

milt

Knight
Random Letters

What would be the best way to generate a random letter? Would using Random to generate an ASCII code and then convert to char work? Is there an easier way?
 

arul

Sorceror
I don't know whether it's the best way or not, but at least it's working :)

Code:
[COLOR="Teal"]Random[/COLOR] r = [COLOR="Blue"]new[/COLOR] [COLOR="Teal"]Random[/COLOR]();
[COLOR="#0000ff"]char[/COLOR] random = ([COLOR="#0000ff"]char[/COLOR])(r.NextDouble() > 0.5 ? r.Next( 65, 90 ) : r.Next( 97, 122 ));
 

Dipset

Wanderer
Maybe you could make a string array and fill it with the alphabet. then ask for a random between 0 and 27. The random number would be the index for the letter in the array.
 
Top