Solved

create random number Javascript based on mouse position

Posted on 2014-02-14
2
555 Views
Last Modified: 2014-03-11
Hi

want to create a random number between 1 and 0.5 based on mouse X position.

if the x posiion is over to left of screen i want the number to decrease and increase if mouse dragged to the right

How can i do this with javascript/jquery

Thanks
0
Comment
Question by:coolispaul
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 39858913
Not sure I follow. Maybe explain in more detail what you need.

Do you want to generate a random number between 0.5 and 1 and then decrease if the mouse is over the left and increase it if it's over the right - what do you want to increase and decrease it to.

How do you want to track the X position of the mouse - click, move etc.

This will generate a random number between 0.5 and 1 - rounded to 2 places:

myNumb = (parseFloat(Math.random() / 2) + parseFloat(0.5)).toFixed(2);

Open in new window

0
 
LVL 9

Accepted Solution

by:
Sar1973 earned 500 total points
ID: 39864699
To create a number between 0.5 and 1:
var myRND=0.5*(Math.random()-1);
But if you want to convert the mouse X position to a range between 0.5 and 1 (and then not to get a random number):
var myXSIZE=0.5+event.clientX/(480*2); //IF YOUR SCREEN IS 640X480 IN RESOLUTION
0

Featured Post

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question