Web Hosting, Design, & Coding forum


How can I get same variable amount from PHP code?

by Hesham_3del / October 26, 2012 10:55 PM PDT

Hello fellow people, I've got a tiny problem.

I want to send POST request, but I can't get one parameter.

The parameter I want is in the PHP code:

"r" : Math.random()

How can I get the same amount?

Discussion is locked
You are posting a reply to: How can I get same variable amount from PHP code?
The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our CNET Forums policies for details. All submitted content is subject to our Terms of Use.
Track this discussion and email me when there are updates

If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.

You are reporting the following post: How can I get same variable amount from PHP code?
This post has been flagged and will be reviewed by our staff. Thank you for helping us maintain CNET's great community.
Sorry, there was a problem flagging this post. Please try again now or at a later time.
If you believe this post is offensive or violates the CNET Forums' Usage policies, you can report it below (this will not automatically remove the post). Once reported, our moderators will be notified and the post will be reviewed.

All Answers

Collapse -
Re: same amount
by Kees_B Forum moderator / October 26, 2012 11:34 PM PDT

An 'amount' is an amount of money, so let's assume you mean 'number'. A random number is a random floating point number >=0 and < 1. And, being random, it's always different. So it's impossible to get "the same".


Collapse -
My reply ;)
by Hesham_3del / October 27, 2012 3:04 AM PDT
In reply to: Re: same amount

I want to get the exact same amount of "r"

Collapse -
You can't.
by R. Proffitt Forum moderator / October 27, 2012 3:21 AM PDT
In reply to: My reply ;)

But if you put the value into variable you can get a new random when you feel like it.

Collapse -
by amanodigma / December 13, 2012 3:14 PM PST
In reply to: You can't.

code please

Collapse -
by R. Proffitt Forum moderator / December 15, 2012 1:41 AM PST
In reply to: code

Yes please code that.

Collapse -
Code please
by swisse / November 14, 2012 3:01 AM PST

May we please look at the code?

Collapse -
Clarification needed.
by Khanalabhi / November 15, 2012 12:14 PM PST

Math.random() is a javascript command. So I'm assuming you're sending the random number that is generated from javascript over to a php page. If you use POST action for it, you can access it from the php page using
$r = $_POST['r'];
Ps. An expected same random number is an oxymoron. Please do elaborate what you are trying to do.

Collapse -
The real truth about random numbers...
by ironman2819 / December 26, 2012 2:48 AM PST
In reply to: Clarification needed.

...while all the code wizards out here are answering this question or requesting the code for this answer it is important to remember the truth about "random()"

...generating random numbers DOES NOT GUARANTEE that you will only see any given number once and only once... the reason is because of the function itself.

When you ask for random numbers, you are asking for a number to be picked without pattern, or by chance, or without consideration to the previous or next number to be picked. But if you really want a number to be generated once and only once, then random is not the function for you.

For a number to be used once and only once (even among a trillion other numbers) then that number must be considered UNIQUE. By using random, you are asking for any number (whether in a range or not) and you don't care which one... but most people when using random number generation are doing so under the expectation that the numbers generated will never be seen again.

That isn't how random numbers work, that is how unique numbers work.

Popular Forums
Computer Newbies 10,686 discussions
Computer Help 54,365 discussions
Laptops 21,181 discussions
Networking & Wireless 16,313 discussions
Phones 17,137 discussions
Security 31,287 discussions
TVs & Home Theaters 22,101 discussions
Windows 7 8,164 discussions
Windows 10 2,657 discussions

Does BMW or Volvo do it best?

Pint-size luxury and funky style

Shopping for a new car this weekend? See how the BMW X2 stacks up against the Volvo XC40 in our side-by-side comparison.