473,569 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need a string of random numbers

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.

Jun 5 '06 #1
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)));

Jun 6 '06 #2
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? :)

Jun 6 '06 #3

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 ;-)

Jun 6 '06 #4
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/

Jun 6 '06 #5
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
Jun 6 '06 #6
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) ?

Jun 6 '06 #7
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.

Jun 6 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3006
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
14
1450
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
21
2996
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
3
1314
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...
4
2311
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;
104
5090
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...
12
5203
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?
1
1489
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...
4
1631
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...
13
2210
Deathwing
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....
0
7612
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...
0
7922
Oralloy
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. ...
0
8119
jinu1996
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...
1
7668
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...
0
7964
tracyyun
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...
1
5509
isladogs
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...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2111
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
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.