Hi,
Need a string of random numbers from 1 to 6 generated by php, none of
the numbers repeat, e.g. 142635, and NOT 114255.
Thanks. 7 1376
TristaSD wrote: Hi,
Need a string of random numbers from 1 to 6 generated by php, none of the numbers repeat, e.g. 142635, and NOT 114255.
Thanks.
str_shuffle(imp lode('', range(1, 6)));
Chung Leong wrote: TristaSD wrote: Hi,
Need a string of random numbers from 1 to 6 generated by php, none of the numbers repeat, e.g. 142635, and NOT 114255.
Thanks.
str_shuffle(imp lode('', range(1, 6)));
Subtle hint? :)
Bent Stigsen wrote: Chung Leong wrote:
TristaSD wrote: Hi,
Need a string of random numbers from 1 to 6 generated by php, none of the numbers repeat, e.g. 142635, and NOT 114255.
Thanks.
str_shuffle(imp lode('', range(1, 6)));
Subtle hint? :)
A to-the-point post desires a to-the-point reply ;-)
Bent Stigsen wrote: Chung Leong wrote:
<snip> str_shuffle(imp lode('', range(1, 6)));
Subtle hint? :)
echo str_shuffle('12 3456');
print_r(range(1 , 6));
echo implode('', range(1, 6));
--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/
R. Rajesh Jeba Anbiah wrote: Bent Stigsen wrote: Chung Leong wrote: <snip> > str_shuffle(imp lode('', range(1, 6)));
Subtle hint? :)
echo str_shuffle('12 3456'); print_r(range(1 , 6)); echo implode('', range(1, 6));
All work and no fun makes Jack a dull boy.
I think Trista would have figured it out, once looking in the manual.
/Bent
Thanks, all. Here's how I used this. If I weren't so lazy, I'd count
the number of pics in a folder so that a user can just upload a pic and
not mess with the $total_number variable in the code :)
<?
$total_number = 6; // Total number of pics
for ($i = 1; $i <= $total_number; $i++) {
$string_to_shuf fle = $string_to_shuf fle . $i;
}
$string_to_shuf fle = str_shuffle ($string_to_shu ffle);
for ($counter = 0; $counter <= strlen ($string_to_shu ffle) - 1;
$counter++) {
echo ("<img src='images/gaslogo_");
echo (substr ($string_to_shu ffle, $counter, 1));
echo (".jpg' alt='some ALT text' ");
echo (substr ($string_to_shu ffle, $counter, 1));
echo ("' /><br />\n");
}
?>
Also, is it a good practice to break echo's like that, or should I
write them as one echo statement (sorry for the drift) ?
TristaSD wrote: Thanks, all. Here's how I used this. If I weren't so lazy, I'd count the number of pics in a folder so that a user can just upload a pic and not mess with the $total_number variable in the code :)
<? $total_number = 6; // Total number of pics
for ($i = 1; $i <= $total_number; $i++) { $string_to_shuf fle = $string_to_shuf fle . $i; }
$string_to_shuf fle = str_shuffle ($string_to_shu ffle);
for ($counter = 0; $counter <= strlen ($string_to_shu ffle) - 1; $counter++) { echo ("<img src='images/gaslogo_"); echo (substr ($string_to_shu ffle, $counter, 1)); echo (".jpg' alt='some ALT text' "); echo (substr ($string_to_shu ffle, $counter, 1)); echo ("' /><br />\n"); } ?>
Also, is it a good practice to break echo's like that, or should I write them as one echo statement (sorry for the drift) ?
If you do it the first way you will go blind. If you do it the second
way, the leprechauns will get you. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kent |
last post by:
What am I missing here. Why doesn't this produce a random string. It is
kind of random.
<%
Const ConstantLower = "bcdfghjklmnpqrstvwxyz"
Const VowelLower = "aeiou"
Const Numbers = "0123456789"
Const NumOfChar = 12
Dim x : x = 0
|
by: Nikola |
last post by:
I need a function that reads from a txt file and randomly chooses a line
from which retrieves a string (with spaces) and returns it to main function.
thx
|
by: Marc Dansereau |
last post by:
Hi all
I am new to this forum and to the c programming language.
If I understand, the random() function in C return numbers that follow a
uniform distribution U(0,1). Can somebody know how to generate a set of
random number that follow a normal distribution N(0,1) ? I am develloping
on power4 machine running AIX.
Thank you for your help
|
by: Corey Dyke |
last post by:
K here's the situation, attached is a copy of the lab i have due next week.
But I won't be around for the next few days, so I 've gotta get it done
ASAP. but it's driving me crazy.
We have to design a windows application for children to use for simple
arithmetic. They must have an option button to bring up a modal dialog
which allows them...
|
by: Aaron |
last post by:
I like like to randomly output phone numbers seperated by \ and / from a string
s = "\231-3423/\453-1234/\231-3473/\231-3474/"
private string GetPhoneNum()
{
s = "\231-3423/\453-1234/\231-3473/\231-3474/"
//randomly pick a phone num from string.
n = randomNum;
| |
by: fieldfallow |
last post by:
Hello all,
Is there a function in the standard C library which returns a prime
number which is also pseudo-random?
Assuming there isn't, as it appears from the docs that I have, is there
a better way than to fill an array of range 0... RAND_MAX with
pre-computed primes and using the output of rand() to index into it to
extract a random...
|
by: Jim Michaels |
last post by:
I need to generate 2 random numbers in rapid sequence from either PHP or
mysql.
I have not been able to do either. I get the same number back several times
from PHP's mt_rand() and from mysql's RAND().
any ideas?
I suppose I could use the current rancom number as the seed for the next
random number. but would that really work?
|
by: c_323_h |
last post by:
Hi, I need this fast 10pm today. I need help with some code. I am working on this program...a user inputs an integer (For example, 50) between 1 and 100. I have a for loop that generates random numbers between 1 and 100 and iterates according to user input. Now i need to figure out the number of consecutive times that a random numbers occurs...
|
by: UMstudent |
last post by:
I'm working on this program for class where I have to an amount of numbers that are randomly picked from 0 - 50. So what I have done is say there are 20 slots in my array so I'm trying to generator 20 random numbers for the array between 0-50 however I've ran into a few problems. Mainly figuring out how to make it print 20 seperate completely...
|
by: Deathwing |
last post by:
Hello,
I'm fairly new to python and have only been playing around with it for one week actually. It's my first attempt at programming and I'm trying to generate some random floats and then have the results of this random generation be filled into a .txt file. So far I have only been able to generate random intergers and create a blank .txt....
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |