digitalmars.D.learn - How to generate a random string ...
- Robert burner Schadek (8/8) Mar 16 2015 ... from all Unicode characters in an idiomatic D way?
- bearophile (5/6) Mar 16 2015 Perhaps by rejection? I mean, generating a uint, test if it's a
- Robert burner Schadek (2/4) Mar 16 2015 hm, that must not even terminate.
- Gary Willoughby (6/14) Mar 16 2015 I guess it depends on the encoding?
- Robert burner Schadek (8/12) Mar 16 2015 This will not work as the caller has to specify the code range. I
- Panke (8/16) Mar 17 2015 You'll need two things. A uniform distribution of { 0 ... 113,020
... from all Unicode characters in an idiomatic D way?
(std.interal.unicode_*)
```
T genUnicodeString(T)(size_t minChars, size_t maxChars)
if(isSomeString!T) {
...
}
```
Mar 16 2015
Robert burner Schadek:... from all Unicode characters in an idiomatic D way?Perhaps by rejection? I mean, generating a uint, test if it's a character and repeat until the result is true. Bye, bearophile
Mar 16 2015
On Monday, 16 March 2015 at 18:48:29 UTC, bearophile wrote:Perhaps by rejection? I mean, generating a uint, test if it's a character and repeat until the result is true.hm, that must not even terminate.
Mar 16 2015
On Monday, 16 March 2015 at 13:33:55 UTC, Robert burner Schadek
wrote:
... from all Unicode characters in an idiomatic D way?
(std.interal.unicode_*)
```
T genUnicodeString(T)(size_t minChars, size_t maxChars)
if(isSomeString!T) {
...
}
```
I guess it depends on the encoding?
Some references:
http://stackoverflow.com/questions/23853489/generate-a-random-unicode-string
http://www.bonf.net/2009/01/14/generating-random-unicode-strings-in-c/
Mar 16 2015
On Monday, 16 March 2015 at 22:19:52 UTC, Gary Willoughby wrote:I guess it depends on the encoding?No the character itself are encoding independent.Some references: http://stackoverflow.com/questions/23853489/generate-a-random-unicode-stringThis will not work as the caller has to specify the code range. I want to specify the string length and the random use is not even uniform (see channel 9 link) http://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmfulhttp://www.bonf.net/2009/01/14/generating-random-unicode-strings-in-c/I'm not use how that is going to give me the 113,021 unicode defined characters let alone in a uniform way.
Mar 16 2015
On Monday, 16 March 2015 at 13:33:55 UTC, Robert burner Schadek
wrote:
... from all Unicode characters in an idiomatic D way?
(std.interal.unicode_*)
```
T genUnicodeString(T)(size_t minChars, size_t maxChars)
if(isSomeString!T) {
...
}
```
You'll need two things. A uniform distribution of { 0 ... 113,020
}, this should be easy using phobos. And a mapping of { 0 ...
113,020 } -> unicode ( or UTFX directly ). Since the unicode
planes or not connected, this might involve some kind of table.
Then just generate your uniform distribution and apply the
mapping.
Mar 17 2015









"Robert burner Schadek" <rburners gmail.com> 