I want to generate some random text from a given a text…want to get the text of same size and format as the given text.
Note: You may not need this …but reason I’m doing this is I want to mask some sensitive data in my page before sending to someone…want to keep mask text of same size.
Sorry - perhaps I’ve misunderstood. I thought you were looking to generate text to fill the same amount of space, so you could use the word count to get a close approximation and just adjust a little as necessary.
Just as an afterthought, I tried downloading the wordcounter site as a complete webpage (as described yesterday). On opening the page up locally, its functionality still works fine for what you need (I tried it in IE11 and Chrome). So if you’re at all concerned about using an open internet site due to the sensitivity of your content, then try it that way.
Does the text need to fill exactly the same space? Different characters take up different amounts of space in most fonts and so switching characters randomly can affect the length of the text even though it contains the same number of characters.
For example compare the following two 10 character strings
iiiiiiiiii
MMMMMMMMMM
it the two strings need to be as close as possible to the same length then perhaps you could convert the entire text into an array of single characters, shuffle it, and then convert the array back to text. The resultant length will possibly be slightly different from the original depending on where the spaces end up but it will likely be closer in length to the original than if you also substitute different width characters.
For example: The rain in Spain falls mainly on the plain.
could become r .hl yT ian apeli mei paiaotnnsnlnahlSf n i
providing text of exactly the same length