This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Random URL without repetition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Random URL without repetition" Watch "Random URL without repetition" New topic
Author

Random URL without repetition

Alice Poe
Greenhorn

Joined: Apr 22, 2014
Posts: 1
Hey, I have so little java knowledge and I need to use it for my thesis.
I have three websites and I want to randomly generate them. First one works perfectly fine with

<script type="text/javascript">
function randomlinks(){
var myrandom=Math.round(Math.random()*2)
var links=new Array()
links[0]="link1"
links[1]="link2"
links[2]="link3"


window.open(links[myrandom]);
}
</script>

Once one of them is generated, I don't want it to repeat itself.
I have searched a lot, but I do not seem to get a clear answer or I simply do not understand so technical language.
Any help would be appreciated. Thanks in advanced.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 4094
    
  18

The solution would be to remove that link from your array after you've opened it. Take a look at the splice() method.

By the way, did you know that JavaScript and Java are two completely unrelated languages? I'm going to move this to the JavaScript forum.

Welcome to CodeRanch!


The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Random URL without repetition
 
It's not a secret anymore!