Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Random generation using defined data

Author
Message
Sardine
19
Years of Service
User Offline
Joined: 5th Sep 2005
Location: U K
Posted: 20th Oct 2005 02:16
Hello,

I am trying to figure out how I can use a random generated number to link to a string. For instance if I have 3 cities and a quest is for someone to begin randomly from A, B or C to arrive in A, B or C, I cannot figure out a way to print "Go from city " (A, B, C,) "And arrive at City "(A, B, C).

Is the secret in arrays or something? My effort used strings, such to say
City1$ = A

etc.

Therefore
I need convert (RND) 1, 2 ,3 to city names within a sentence. "Go from " "to " etc.

I can't find the technique in the tutorials. Any help is appreciated.

Thanks
NanoBrain
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 20th Oct 2005 05:53
Sardine,

Let's use a single string array, named cityname$(2), which as you can see has 3 slots(0 is also a slot).



Now, fill the array with the names of the cities, each into a single slot.



The RND function will return a number between 0 and the number you supply it. Therefore, rnd(2) will return a number between 0 and 2, making a match to either slot of our array.

Below is the end of the code. Concatenate the chosen array slot string into the middle of your constant strings.





+NanoBrain+
Sardine
19
Years of Service
User Offline
Joined: 5th Sep 2005
Location: U K
Posted: 20th Oct 2005 14:28
Thank you NanoBrain

Just what I was looking for. Much simpler than what I had in mind.

Login to post a reply

Server time is: 2024-09-24 07:30:26
Your offset time is: 2024-09-24 07:30:26