Coder Social home page Coder Social logo

How can i get a random word ? about dawgsharp HOT 4 CLOSED

bzaar avatar bzaar commented on May 30, 2024
How can i get a random word ?

from dawgsharp.

Comments (4)

bzaar avatar bzaar commented on May 30, 2024

There is no such method currently, but it can be done. Off the top of my head, I can think of two ways of implementing this:

  1. Start at the root node and walk down the graph, choosing a child randomly. Unfortunately, this won't give you a uniform distribution. Longer words will appear less frequently.

  2. To get a more uniform distribution across all DAWG items, you could point randomly into the children array and then find the path from the root to this particular child.

As this is just my hobby project, I can't plan when I get around to implementing this.

from dawgsharp.

kenofori avatar kenofori commented on May 30, 2024

@bzaar i liked the children array approach, i can already see this array populated in debug view, so can you please give me a rough idea how can find the path if i choose a random child for example

{
charIndex: 18
index: 112350
}

from dawgsharp.

bzaar avatar bzaar commented on May 30, 2024

I've committed a first (suboptimal) version of GetRandomItem. The word distribution may not be fully uniform but it shouldn't be too bad. Please see if this fits your requirements.

from dawgsharp.

kenofori avatar kenofori commented on May 30, 2024

Thanks @bzaar
Having something is better than having nothing.

from dawgsharp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.