SlideShare a Scribd company logo
1 of 9
Random Number Generation
Var randomValue = Math.random();
random()
 The Random Method returns number between 0 (inclusive) and 1 (exclusive).
 Math.random();
 There are no parameters for the method random().
Shifting and Scaling
 The range of values produced directly by a random is often different than what is needed
in a specific application.
 Eg:
 Dice
 Coin Tosing
Scaling and Shifiting
Math.floor( 1 + Math.random() * 6 )
 Here, Math.random is multiplied with 6, so that we get a range from 0.0 to 6.0
 This is called scaling.
 Adding 1(here) to the obtained value is called shifting.
 Math.floor() is used to determine the closest integer not greater than the argument value
 Eg: Math.floor(6.75) is 6 and Math.floor(1.89) is 1
 (Program 1)
Displaying Random Images
 Web content that varies randomly can add dynamic, interesting effects to a page.
 Alert()
 Prompt()
 Scripts are often used to respond to user initiated events.
Has Limited Features In receiving input from the
user
Events
 Click Event
 Occurs when the user clicks on the button.
This style of Programming is known as event-driven programming
Event-Driven Programming
User interacts with the web
page element
Script is notified of the event
Script processes the event
Event Handler
 The Function that’s called when an event occurs is known as the event
handler.
 When a GUI event occurs in a form, the browser calls the specified event-
handling function.
 Before any event can be processed, each element must know which event-
handling function will be called when a particular event occurs.
Time for some real Examples

More Related Content

Similar to Random number generation

CSE 103 Project Presentation.pptx
CSE 103 Project Presentation.pptxCSE 103 Project Presentation.pptx
CSE 103 Project Presentation.pptx
TasnimSaimaRaita
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]
Palak Sanghani
 
Operators in c language
Operators in c languageOperators in c language
Operators in c language
Amit Singh
 

Similar to Random number generation (20)

Csci101 lect02 selection_andlooping
Csci101 lect02 selection_andloopingCsci101 lect02 selection_andlooping
Csci101 lect02 selection_andlooping
 
CSE 103 Project Presentation.pptx
CSE 103 Project Presentation.pptxCSE 103 Project Presentation.pptx
CSE 103 Project Presentation.pptx
 
Csci101 lect03 algorithms_i
Csci101 lect03 algorithms_iCsci101 lect03 algorithms_i
Csci101 lect03 algorithms_i
 
JavaScript 101
JavaScript 101JavaScript 101
JavaScript 101
 
3 analysis.gtm
3 analysis.gtm3 analysis.gtm
3 analysis.gtm
 
Mcs 011 solved assignment 2015-16
Mcs 011 solved assignment 2015-16Mcs 011 solved assignment 2015-16
Mcs 011 solved assignment 2015-16
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solution
 
Xi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programsXi CBSE Computer Science lab programs
Xi CBSE Computer Science lab programs
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
 
functions2-200924082810.pdf
functions2-200924082810.pdffunctions2-200924082810.pdf
functions2-200924082810.pdf
 
Python programming workshop session 2
Python programming workshop session 2Python programming workshop session 2
Python programming workshop session 2
 
Recommender Systems
Recommender SystemsRecommender Systems
Recommender Systems
 
Course project solutions 2018
Course project solutions 2018Course project solutions 2018
Course project solutions 2018
 
Software fundamentals
Software fundamentalsSoftware fundamentals
Software fundamentals
 
C – operators and expressions
C – operators and expressionsC – operators and expressions
C – operators and expressions
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]
 
Operators
OperatorsOperators
Operators
 
Operators in c language
Operators in c languageOperators in c language
Operators in c language
 
3.3 - The Math Object.pptx
3.3 - The Math Object.pptx3.3 - The Math Object.pptx
3.3 - The Math Object.pptx
 
Tomato Classification using Computer Vision
Tomato Classification using Computer VisionTomato Classification using Computer Vision
Tomato Classification using Computer Vision
 

Recently uploaded

Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
chumtiyababu
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 

Recently uploaded (20)

Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptx
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 

Random number generation

  • 1. Random Number Generation Var randomValue = Math.random();
  • 2. random()  The Random Method returns number between 0 (inclusive) and 1 (exclusive).  Math.random();  There are no parameters for the method random().
  • 3. Shifting and Scaling  The range of values produced directly by a random is often different than what is needed in a specific application.  Eg:  Dice  Coin Tosing
  • 4. Scaling and Shifiting Math.floor( 1 + Math.random() * 6 )  Here, Math.random is multiplied with 6, so that we get a range from 0.0 to 6.0  This is called scaling.  Adding 1(here) to the obtained value is called shifting.  Math.floor() is used to determine the closest integer not greater than the argument value  Eg: Math.floor(6.75) is 6 and Math.floor(1.89) is 1  (Program 1)
  • 5. Displaying Random Images  Web content that varies randomly can add dynamic, interesting effects to a page.  Alert()  Prompt()  Scripts are often used to respond to user initiated events. Has Limited Features In receiving input from the user
  • 6. Events  Click Event  Occurs when the user clicks on the button. This style of Programming is known as event-driven programming
  • 7. Event-Driven Programming User interacts with the web page element Script is notified of the event Script processes the event
  • 8. Event Handler  The Function that’s called when an event occurs is known as the event handler.  When a GUI event occurs in a form, the browser calls the specified event- handling function.  Before any event can be processed, each element must know which event- handling function will be called when a particular event occurs.
  • 9. Time for some real Examples

Editor's Notes

  1. In Slide Show mode, click the arrow to enter the PowerPoint Getting Started Center.