Solved

create random number Javascript based on mouse position

Posted on 2014-02-14
2
514 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
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

813 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now