Web Hosting, Design, & Coding

Question

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?

Answer This Ask For Clarification
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 -
Answer
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".

Kees

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.
Bob

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

code please

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

Yes please code that.

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

May we please look at the code?

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

Hesham,
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.
Abhi

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
icon
Computer Help 47,885 discussions
icon
Computer Newbies 10,322 discussions
icon
iPhones, iPods, & iPads 3,188 discussions
icon
Security 30,333 discussions
icon
TVs & Home Theaters 20,177 discussions
icon
HDTV Picture Setting 1,932 discussions
icon
Phones 15,713 discussions
icon
Windows 7 6,210 discussions
icon
Networking & Wireless 14,510 discussions

Tech for the holiday

Find recipes for July 4 with these foodie apps

The Fourth of July means fireworks, fun and food. If you're planning on a barbecue this weekend, we've got the apps to help you find holiday-inspired recipes.