473,405 Members | 2,171 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.

use math.random to generate license plate numbers

I"m really really confused on how to do this problem. I need to use math.random and type-casting to print out 20 license plates but I'm just really lost. Can anyone help me out?


Use Java’s type-casting mechanism to write a program that prints 20
“random” license plate numbers, each one consisting of three randomly-
chosen digits followed by three randomly chosen upper-case letters. The
first digit cannot be zero.
Jul 8 '08 #1
5 6126
r035198x
13,262 8TB
Start by writing down your algorithm then.
Jul 8 '08 #2
JosAH
11,448 Expert 8TB
The Random class has a bit more convenient methods than the Math class
but it doesn't matter much; try to come up with a way to generate a number in
the interval [n,m) and most of the job is done.

kind regards,

Jos
Jul 8 '08 #3
BigDaddyLH
1,216 Expert 1GB
Another hint: one way to choose a character from a sequence of characters is to start with a String containing those characters and then randomly select the index of a character in that string:
Expand|Select|Wrap|Line Numbers
  1. String vowels = "aeiouy";
  2. int index = ...
  3. char selected = ...
  4.  
Jul 8 '08 #4
also add your already generated plates to an arraylist, and check with each new plate it doesn't already exists, so you're sure you won't have two identical plates.
Jul 8 '08 #5
JosAH
11,448 Expert 8TB
also add your already generated plates to an arraylist, and check with each new plate it doesn't already exists, so you're sure you won't have two identical plates.
Better add them to a Set then ...

kind regards,

Jos
Jul 9 '08 #6

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

Similar topics

2
by: Murat Tasan | last post by:
here is the situation... i have an array... and i select something from random from it. i pick a random number x by using Math.random() and multiplying it by the length of the array. but this...
0
by: Tony Stephens | last post by:
I have a database table that contains a set of numbers (set X). I need to be able to generate/export a random set of survey numbers (set C) from set A with IDs that aren't in set B. Where set A is...
4
by: Robert Scheer | last post by:
Hi. Reading about the Math.random method I saw that by default it generates between 0 and 1. To generate numbers between a greater range I can use these syntaxes: x = Math.random()/10 x =...
23
by: Thomas Mlynarczyk | last post by:
I remember there is a programming language where you can initialize the random number generator, so that it can - if you want - give you the exactly same sequence of random numbers every time you...
16
by: Jason | last post by:
Hi, I need a way to use random numbers in c++. In my c++ project, when using the mingw compiler I used a mersenne twister that is publicly available and this did its job well. Now I have...
6
by: RobG | last post by:
I am writing a script to move an absolutely positioned element on a page by a factor using style.top & style.left. The amount to move by is always some fraction, so I was tossing up between...
21
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...
34
by: Johannes Baagoe | last post by:
About Math.random(), ECMA 262 just says "Returns a number value with positive sign, greater than or equal to 0 but less than 1, chosen randomly or pseudo randomly with approximately uniform...
9
by: DaiOz | last post by:
Hi guys im doing a course which includes some JavaScript and I need help with the following question please, The code I have so far is below but I don't think its right please help as I need...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.