Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // My custom random random class for generating random integer number
- // and randomly selecting item from list or array
- // inspired by Python
- class Random{
- constructor(list=null){
- this.list=list;
- }
- choice(){
- let num = Math.random()*this.list.length;
- return this.list[parseInt(num)];
- }
- randint(start,end){
- let new_length = end-start;
- let numInt = Math.random(start,end)*new_length;
- return parseInt(numInt);
- }
- }
- let greetings = ['Good Morning','Good Afternoon',"Good Night",'Good Bye',"Let us meet"];
- let random = new Random(greetings);
- var message ;
- message = random.choice();
- console.log(message);
- console.log(random.randint(1,20))
Add Comment
Please, Sign In to add comment