View Full Version : adding randomal "0" to string

10-09-2007, 04:53 PM
i got a string- for example the word "CodingForums"
i want somehow to add randomal char- for example "0", 3 times
the output can look like this-
"0C0odi0ngForums" "Co0ding0Foru0ms" "Co0din0gFor0ums" "0CodingForums00"
what is the best way to do this?:rolleyes:

10-09-2007, 05:16 PM
Hey Sasha --

You can use RND, RANDOMIZE, LEFT, and MID to solve this problem.

NOTE: Rnd (Random) is not always random... :(

<% strAddChar = "Coding Forums"
strToAdd = "0"
for x=1 to 3 'where 3 = the number of times you want to add a character
y = Int(Int(Rnd) - (len(strAddChar) + 1) * Rnd + len(strAddChar) + Rnd)
strAddChar = LEFT(strAddChar,y) & strToAdd & MID(strAddChar,y+1,len(strAddChar))
response.write strAddChar
response.flush %>

YOU MAY RECEIVE AN ERROR!!! That's because Random isn't always random.

10-09-2007, 06:55 PM
To ensure that you get a random number you MUST use the Randomize statement before you use Rnd. Otherwise the numbers will display in the same sequence every time

10-10-2007, 10:23 AM

thank u !

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum