I need to read in text randomly from a text file, so does anybody have code for that?
pretend the text file is called CommunityChest.txt

i prefer the use of the scanner class or the use of text readers

thank you!

the text file is included below if anybody needs it
[i'm programming a basic monopoly game]

Caught hacking computers!
Pay $1000

Swimming Tournament!
Advance to Swimming Pool

Go to directly to Jail
Do not pass go, do not collect $200

Got first place at a Debate tournament!
Collect $150

Broke ankle while playing Badminton!
Pay $300

Sprint to Go
Collect $200

Bought roller blades!
Advance three spaces

AP Exams!
Advance to Calculus

AP Testing Time!
Pay $400

Recommended Answers

All 2 Replies

Read all the file in an array or a Vector and generate a random number from 0 to size-1. Then take from the array the element that is at the place of generated number.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.