Comp 110 random(_)

The 'random(_)' Function

Like all of our introcs functions, random needs to be imported!

import { random } from "introcs"; 

This is what our function definition looks like!

let random = (floor: number, ceiling: number): number => {

     //...

}

random takes in two number arguments that act as the 'floor' and the 'ceiling'

The number that is returned as a result from the function will return a randomly generated number between the floor and the ceiling.

The floor and the ceiling are inclusive, meaning the generated number will be >= floor and <= ceiling.

Example of use:

​let whereShouldIStudy = () : string => {
     let randomNumber = random(1,4);
     if(randomNumber === 1) {
          return "Old Well";
     } else if(randomNumber === 2) {
          return "Bell Tower";
     } else if(randomNumber === 3) {
          return "Dean Dome";
     } else {
          return "Franklin Street";
     }
}
//whatever number is generated will determine what string is printed!