vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   [PHP] rand() for large numbers (https://vborg.vbsupport.ru/showthread.php?t=113231)

Nullifi3d 04-17-2006 12:49 PM

[PHP] rand() for large numbers
 
I need to generate a random number (with specified min and max) for small and large numbers. I'm using rand(*, *) right now and it doesn't seem to work with numbers in the billions. They go into the negative. What can I use instead?

DrewM 04-17-2006 01:45 PM

<a href="http://us3.php.net/manual/en/function.rand.php" target="_blank">http://us3.php.net/manual/en/function.rand.php</a>

Nullifi3d 04-17-2006 02:28 PM

I have already checked the php.net rand function manual. The only thing mentioned that seems to be even remotely close to what I am achieving is the statement:
Quote:

Note: On some platforms (such as Windows) RAND_MAX is only 32768. If you require a range larger than 32768, specifying min and max will allow you to create a range larger than RAND_MAX, or consider using mt_rand() instead.
This says to either do what I am already doing (specifying a min and max) or using mt_rand() instead. Which on my server mt_rand() has the same MAX_RAND as rand() (2147483647). mt_rand() is faster though, so I should use it anyways right?

So how do I generate a random number between two numbers in the tens of billions?

DrewM 04-17-2006 02:39 PM

sorry but I can't help you any more I thought that would have helped

Nullifi3d 04-17-2006 02:48 PM

It's ok. It's quite strange. The manual states that if you specify a min and max then you can generate a number larger then the RAND_MAX, but it doesn't work with trying to generate a number between 90% and 95% of a number in the tens of billions.
PHP Code:

$armyinfo['damage'] = mt_rand( (.90 $armyinfo['strike_action']), (.95 $armyinfo['strike_action']) ); 



All times are GMT. The time now is 03:37 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00941 seconds
  • Memory Usage 1,719KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete