Click here to Skip to main content
15,889,879 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hello guys,

I have one problem, i build one game, and for example, we have one string array:
string[] words = {"one word", "seconds word", "third word", "fourth word ..."};

i want to select randomly word in this array using Random class, but when i use this method:
C#
public string GetWord()
        {
            return words[random.Next(words.Length)];
        }

and secondly i want do draw it, like spriteBatch.DrawString(spriteFont, GetWord(), new Vector2(0, 0), Color.White)
it makes me to cry ... it selected random words, but random word in every screen ...

Could you give me an advice, how can i fix it? I want to select randomly string, and words will changing when one object intersects with other object.

Thanks very much for advice

Marek
Posted
Comments
Sergey Alexandrovich Kryukov 25-Mar-14 18:40pm    
Not clear. Fix what?
What are you complaining about? The words are random, as you wanted, so what else would you need? And if you do, why not getting what you need?
What object intersect with what? and so on...
—SA
ravikhoda 26-Mar-14 1:19am    
do you want to generate capecha code or something like that ?
CPallini 26-Mar-14 4:09am    
What's wrong in the code you posted? What is the incorrect observed behaviour?

1 solution

I would like to randomly generate one string from array, i need only this.... im looking forward that you give me good information
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900