Randomized link generator

I have about 500 links ready, what I want to do is I have a website, and on that website there will be a button; When pressed the button will redirect you to a one of the links out of the 500.

(Optional) Not only will that happen but the link will be removed after someone has used it.
Most likely removed from a .txt file where all the links are stored

If you can I would appreciate any help on this subject thanks

1 Like

If you store the links in an array, you can use a random number function to randomly select something from the array. Check out my article.

dev.to is kind of broken for me lol

oh why? #tenchars

The dev.to app won’t respond and the website timed out

lol weird. bcz ur big brain coder I assume you already tried clearing ur cache cookies etc

  • waits for sarcastic “omg i didn’t try that” *
2 Likes

I tried clearing cache but nothing happened. I tried a different device and nothing happened

the bane of all programmers: nothing happened.

Weird, i guess you could email them or something. I emailed them and they helped me fix my markdown.

I think It’s just a problem with Xfinity as they are having an outage.

Group them in a js list, like this: (you will need to put this at the very beginning in order for this to work)

var links = ["this", "that", "ping", "pong"];

then randomize them using this:

window.location = links[Math.floor(Math.random() * links.length)];

or you can put it in a function

function link() {
return links[Math.floor(Math.random() * links.length)];
}

and use it like this:

window.location = link();

I don’t know how you would delete it but you should use node.js

If you want a random link generator, you will probably want a base64 function:

function base64_rand() {
                $chars = "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_-";
                $number1 = rand(1,62);
                $number2 = $number1 - 1;
                $letter = substr($chars, $number2, $number1);
                return $letter[0];
            }
$key = "0";
            for ($x = 0; $x <= 7; $x++) {
                $append = base64_rand();
                $key .= $append;
            }

The code above will give you a random string that is 7 characters long.

More:

oops I thought he was using js haha

Were he say he use the php?

the tags, near the top or the title

1 Like

Oh oops, I thought it was client side lol

Me as well, my internet disconnected last night when I was writing a reply so I just went to bed. Then the next day I realize that it was php :man_facepalming:

1 Like