Skip to content

Too many Underscore is generated. #44

@m-shaka

Description

@m-shaka

Hi. I want to generate string that matchs regex \\w, but generated string contains obviously too many Underscores. Does java.util.Random's unevenness cause this?

The following is sample code. (I'm Sorry, I use Kotlin, not Java)

fun main(args: Array<String>) {
    val value = Generex("\\w{1000}").random()
    val counter = mutableMapOf<Char, Int>()
    for (v in value.toList()) {
        val c = counter.get(v)
        when (c) {
            null -> counter.put(v, 1)
            else -> counter.put(v, c + 1)
        }
    }
    counter.toList().sortedByDescending { it.second }.take(10).forEach {
        println("char: ${it.first}, count: ${it.second}")
    }
}

//    sample result
//    char: _, count: 225
//    char: 3, count: 38
//    char: 8, count: 30
//    char: 4, count: 29
//    char: 9, count: 28
//    char: 5, count: 27
//    char: 1, count: 27
//    char: 7, count: 24
//    char: 2, count: 24
//    char: 0, count: 22

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions