salmannotkhan / typing-test

Typing test website build with React
https://salmannotkhan.github.io/typing-test/
MIT License
189 stars 55 forks source link

Added wordlist for numbers only #11

Closed siddhantmadhur closed 2 years ago

siddhantmadhur commented 2 years ago

Idea: A numbers only mode

Implementation: There can be infinitely cleaner methods to create this so it can be completely random but for convenience sake I made a list of 500+ numbers using the following script and put it in a .json

let arr = [];
for(let i = 0; i < 500; i++ ) {
    const max = 6;
    const length = Math.floor(Math.random() * max)
    const randomInt = Math.floor(Math.random() * 1000000 * length);
    if( randomInt !== 0 ){
        arr.push(`${randomInt}`)    
    }else{
        i = i - 1;
    }
}
console.log(arr);

Limitations: The list is limited to only 500 numbers

Future Ideas: Either directly implement the code into the site or create an improved list with more numbers

salmannotkhan commented 2 years ago

It's a great idea! Maybe something like words as text e.g "One", "Two", "Three" also can be a great idea. But we have to figure out new names for it.

salmannotkhan commented 2 years ago

I'm thinking how we can make this logic more random

siddhantmadhur commented 2 years ago

Is there any way to accept arrays from the main function itself, rather than pull it from a json file

salmannotkhan commented 2 years ago

We can do that in reducer but then whenever someone select number mode it'll recalculate all the numbers

siddhantmadhur commented 2 years ago

Updated the logic

So I updated the code to generate numbers and generated 1290 numbers using it.

let arr = [];
let append = "";
for(let i = 0; i < 100; i++ ) {
    const max = Math.round(Math.random()*8); //decides how long the number is going to be
    if(max>4){
        append = ""; //resets 
        for(let j = 0; j < max; j++){ // loops max amt of times, checking if the new number is equal to the last number or not so its random
            const cursor = Math.round(Math.random() * 9)
            if(append.length>0){
                if(append.charAt(j-1).match(cursor)){
                    j = j-1
                }else{
                    append = append + `${cursor}`
                }
            }else{
                append = append + `${cursor}`
            }
        }
        arr.push(append)
    }else {
        i = i - 1;
    }
}
console.log(arr);

This new code made sure that the numbers being generated have no numbers being repeated in a row, for example: 11111 could not be generated but 12121 could

You can merge this now and I'll create a new PR if i think of a more "randomized" logic.

salmannotkhan commented 2 years ago

Sorry for late reply I was busy at work. I'll test this tonight and merge it.

salmannotkhan commented 2 years ago

Also you should take a look at Javascript crypto API it provides easier way to generate random number

siddhantmadhur commented 2 years ago

No worries Also sure I'll check it out

salmannotkhan commented 2 years ago

I think 1290 numbers are more than enough. Can you reduce it to 300 or something?

salmannotkhan commented 2 years ago

Because it is randomizing these numbers at runtime so it can hurt performance

siddhantmadhur commented 2 years ago

yeah sure

salmannotkhan commented 2 years ago

Looks great

salmannotkhan commented 2 years ago

It looks like CSS requires some minor refinements for numbers mode but that's work for another day 😄