473,405 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

String of 5 unique random letters

24
Hi,
Right now I am working on creating a string of 5 random letters. I have already created the script, it does create a unique random letter but it repeats it 5 times. Here is what I have so far:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. srand();
  3. $random=chr(rand(ord("A"),ord("Z")));
  4. $string="";
  5. for ($i=1;$i<6;$i++) {
  6.     $string .= $random;
  7. }
  8. echo $string;
  9. ?>
  10.  
It diplays 5 of the same letters, I want unique letters.
Jun 25 '08 #1
3 2837
Markus
6,050 Expert 4TB
By calling it as a function produces a unique letter:
Expand|Select|Wrap|Line Numbers
  1. srand();
  2. function randletter()
  3. {
  4.     return  chr(rand(ord("A"),ord("Z")));
  5. }
  6. $string="";
  7. for ($i=1;$i<6;$i++) {
  8.     $string .= randletter();
  9. }
  10. echo $string;
  11.  
Jun 25 '08 #2
miraan
24
Thanks alot, it worked!
Jun 26 '08 #3
Markus
6,050 Expert 4TB
Thanks alot, it worked!
Great!


Regards.
Jun 26 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Bart Nessux | last post by:
number = random.sample(range(count), 1) This makes 'number' into a one entry list (I don't know why as 'count' is an integer). Is there an easy way to convert 'number' back to an int? TIA
21
by: Andreas Lobinger | last post by:
Aloha, i wanted to ask another problem, but as i started to build an example... How to generate (memory and time)-efficient a string containing random characters? I have never worked with...
10
by: John Salerno | last post by:
Can someone tell me what's happening here. This is my code: PUNCT_SPACE_SET = set(string.punctuation + string.whitespace) def filter_letters(original): return ''.join(set(original) -...
12
by: Pascal | last post by:
hello and soory for my english here is the query :"how to split a string in a random way" I try my first shot in vb 2005 express and would like to split a number in several pieces in a random way...
9
by: Robert Mago | last post by:
Is there a way to create a 10 characthers or less, alph-numeric string which is unique. I can't use the guid since its longer then 10 characthers. Also i cannot use a random number, since being...
9
by: Ulterior | last post by:
Hi, everyone, I have a simple problem, which bothers me for some while. I will try to explain it - There is some string, whith different letters in it. Is it possible to analyse this string...
2
by: aboxylica | last post by:
I have a code in which i create a set of alphabets of specified count .Now in particular positions in it i want to embed my choice of letters how do i do it.here is my code def random_seq(): ...
9
by: JimmyJava694 | last post by:
Hey everyone, I need help trying to mutate a String. For example.. I ask the person to input a number. Then I ask them to input a String. (The string they input can be any length, but must...
7
by: Johny | last post by:
I have a string of a variable length and I need to split the string in strings of 6 characters . But if the 6th character is not space then I must split the string at possition before the 6th...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
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...
0
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...

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.