Choosing serveral random and unique numbers
Hi
I'd like to select 9 random numbers out of a set of let's say
1-20. They can't repeat and each has to be saved into a different
variable P1-P9.
Any ideas?
Thanks
Make an array of the numbers 1 through 20.
Shuffle the array.
Take off as many numbers as you need.
Search the forums for shuffle to find out how to shuffle the
array.
Similar Messages
-
Displaying 3 random and unique numbers out of 6
The following program gives me the results in the output panel because I used trace. The problem is that I want these numbers displayed when I click on a button. The numbers should not duplicate when the button is clicked, for example not "3, 3, 2" but "3, 2, 5". Here is the program that randomly selects numbers (which by the way is not mine): (I'll happily donate 15$ to the animal charity of your choice for whoever can give me a hand with this problem, thanks!)
var mynumbers:Array = ["1","2","3","4","5","6"];
var mystuff:Array = [];
var randomCount:Number = 3;
var r:Number;
for (var i = 0; i<randomCount; i++)
r = Math.floor(Math.random() * mynumbers.length);
mystuff[mystuff.length] = mynumbers.splice(r,1);
trace(mystuff);
//and here is my button code
generate_btn.addEventListener(MouseEvent.CLICK, coco);
//3.;
function coco(event:MouseEvent):voidHi
I am trying to replace the numbers in the random script with pictures. I thought that all I had to do was replace the numbers in the array with pictures name.
I am getting the output as picture names instead of actual images. I just started flash a few weeks ago and would appreciate where I am going wrong in the code below. I know, it's a bit ambitious for someone who has no experience in programming or mathematical background. I think, that is the only way to learn. By asking the experts in programming. Otherwise, I just give up, and go back to watching TV.
var mynumbers:Array = ["alfa.jpg","beta.jpg","alfa1.jpg","alfa2.jpg","alfa3.jpg","alfa4.jpg"];
var randomCount:Number = 3;
function shuffle(a:Array) {
var p:int;
var t:*;
var ivar:int;
for (ivar = a.length-1; ivar>=0; ivar--) {
p=Math.floor((ivar+1)*Math.random());
t = a[ivar];
a[ivar] = a[p];
a[p] = t;
//and here is my button code
generate_btn.addEventListener(MouseEvent.CLICK, coco);
//3.;
function coco(event:MouseEvent):void
shuffle(mynumbers);
for(var i:int=0;i<randomCount;i++){
if(!this["tf_"+i]){
this["tf_"+i]=new TextField();
this["tf_"+i].text = mynumbers[i];
addChild(this["tf_"+i]);
this["tf_"+i].y = i*40; -
How to select random and unique number
hi all
suppose i have millions of rows in emp table
i want to select group of empno
group of records would be 10
all records uniquely selected
make sure all records are selected in any Group
thanksBluShadow wrote:
Solomon Yakobson wrote:
3360 wrote:
It is the definition of random that the each value generated has an equal chance of being generated again. A coin toss is random despite the result only having two values.Absolutely. Except one little thing. The above applies if we randomly pick from same set. Now OP asked to randomly select group of objects. This is same as you have a set of unique objects and you randomly pick one and put it in your pocket. Then you randomly pick another object and put it in your pocket. So you end up with a UNIQUE set of randomly picked objects in your pocket. Now DBMS_RANDOM allows to specify low & high value but it doesn't allow to provide something like "pick N values" or except list to mimick "put in your pocket" part. That is why we have to write something like I suggested to OP.
SY.In that case it should just be an answer like...
select * from tablename where rownum <= 10because the order is not guaranteed without an order by clause and therefore that's just as random as needed to meet the requirements. ;)hi BluShadow
rownum surely give unique number of records but it will not A RANDOM....
thanks -
Is there any way to get unique numbers for a label?
Im writing a lottery code and would like to know if there is anyway to get my 6 numbers in my label to be different
this is my code so far
Public Class frmMain
Private randGen As New Random
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub btnSelect_Click(sender As Object, e As EventArgs) Handles btnSelect.Click
Dim intNum1 As Integer
Dim intNum2 As Integer
Dim intNum3 As Integer
Dim intNum4 As Integer
Dim intNum5 As Integer
Dim intNum6 As Integer
intNum1 = randGen.Next(1, 54)
intNum2 = randGen.Next(1, 54)
intNum3 = randGen.Next(1, 54)
intNum4 = randGen.Next(1, 54)
intNum5 = randGen.Next(1, 54)
intNum6 = randGen.Next(1, 54)
lblNumbers.Text = String.Format("{0}, {1}, {2}, {3}, {4}, {5}", intNum1, intNum2, intNum3, intNum4, intNum5, intNum6)
End Sub
End ClassHere's one way using nested For loops. This was tested and it works. It will select 6 different unique numbers between 1 - 54.
Private Sub btnOK_Click(sender As System.Object, e As System.EventArgs) Handles btnOK.Click
Dim num As Integer, dup As Boolean = False
Dim randnum As New Random()
Dim strand As String = ""
Dim itm As String = ""
For x As Integer = 1 To 6
For y As Integer = 1 To 6
num = randnum.Next(1, 55)
itm = num.ToString()
If strand.Contains(itm) Then
dup = True
x = x - 1
Exit For
End If
Next y
If dup = False Then strand &= itm & " "
dup = False
Next x
lblRandom.Text = strand
End Sub
Here is another way using the Shuffle Sort algorithm with an array:
Private Sub btnShuffle_Click(sender As System.Object, e As System.EventArgs) Handles btnShuffle.Click
Dim mix, temp As Integer
Dim randnum As New Random
Dim strand(54) As Integer
lblRandom.Text = ""
For x As Integer = 1 To 54
strand(x) = x
Next
For x As Integer = 1 To 54
mix = randnum.Next(1, 55)
temp = strand(mix)
strand(mix) = strand(x)
strand(x) = temp
Next
For x As Integer = 1 To 6
lblRandom.Text &= strand(x).ToString & " "
Next
End Sub
Solitaire -
Difference b/w index and unique
Hi,
Difference b/w index and unique?hi,
The optional additions UNIQUE or NON-UNIQUE determine whether the key is to be unique or non-unique, that is, whether the table can accept duplicate entries. If you do not specify UNIQUE or NON-UNIQUE for the key, the table type is generic in this respect. As such, it can only be used for specifying types. When you specify the table type simultaneously, you must note the following restrictions:
You cannot use the UNIQUE addition for standard tables. The system always generates the NON-UNIQUE addition automatically.
You must always specify the UNIQUE option when you create a hashed table.
INDEX:
An index can be considered a copy of a database table that has been reduced to certain fields. This copy is always in sorted form. Sorting provides faster access to the data records of the table, for example using a binary search. The index also contains a pointer to the corresponding record of the actual table so that the fields not contained in the index can also be read.
The primary index is distinguished from the secondary indexes of a table. The primary index contains the key fields of the table and a pointer to the non-key fields of the table. The primary index is created automatically when the table is created in the database
You can also create further indexes on a table in the ABAP Dictionary. These are called secondary indexes. This is necessary if the table is frequently accessed in a way that does not take advantage of the sorting of the primary index for the access.
Indexes speed up data selection from the database. They consist of selected fields of a table, of which a copy is then made in sorted order. If you specify the index fields correctly in a condition in the WHERE or HAVING clause, the system only searches part of the index (index range scan).
The system automatically creates the primary index. It consists of the primary key fields of the database table. This means that for each combination of fields in the index, there is a maximum of one line in the table. This kind of index is also known as UNIQUE.
If you cannot use the primary index to determine the result set because, for example, none of the primary index fields occur in the WHERE or HAVINGclauses, the system searches through the entire table (full table scan). For this case, you can create secondary indexes, which can restrict the number of table entries searched to form the result set.
You create secondary indexes using the ABAP Dictionary. There you can create its columns and define it as UNIQUE. However, you should not create secondary indexes to cover all possible combinations of fields.
Only create one if you select data by fields that are not contained in another index, and the performance is very poor. Furthermore, you should only create secondary indexes for database tables from which you mainly read, since indexes have to be updated each time the database table is changed. As a rule, secondary indexes should not contain more than four fields, and you should not have more than five indexes for a single database table.
If a table has more than five indexes, you run the risk of the optimizer choosing the wrong one for a particular operation. For this reason, you should avoid indexes with overlapping contents.
Secondary indexes should contain columns that you use frequently in a selection, and that are as highly selective as possible. The fewer table entries that can be selected by a certain column, the higher that columns selectivity. Place the most selective fields at the beginning of the index. Your secondary index should be so selective that each index entry corresponds to, at most, five percent of the table entries. If this is not the case, it is not worth creating the index. You should also avoid creating indexes for fields that are not always filled, where their value is initial for most entries in the table.
If all of the columns in the SELECT clause are contained in the index, the system does not have to search the actual table data after reading from the index. If you have a SELECT clause with very few columns, you can improve performance dramatically by including these columns in a secondary index.
What is the difference between primary index and secondary index?
http://help.sap.com/saphelp_47x200/helpdata/en/cf/21eb2d446011d189700000e8322d00/frameset.htm
A difference is made between Primary & Secondary indexes to a table. the primary index consists of the key fields of the table and a pointer to the non-keys-fields of the table. The Primary index is generated automatically when a table is created and is created in the datebase as the same times as the table. It is also possible to define further indexes to a table in the ABAP/4 dictionary, which are then referred to as Secondary indexes.
Message was edited by:
Roja Velagapudi -
I created a form with Single Choice fields, 4 days with times listed. But, I want the user to only be able to choose one time, and the time chosen to be unavailable for other users. How do I do this? I have 4 blocks of Single Choice fields in order for the summary page to give me each day in the final report. But, I need the user to be able to make a selection of any day and time and that apointment to no longer be available to future users when they log in. Plus, when the user clicks on the time, they are unable to change their mind and choose another time. Here's the link if you want to see what I'm talking about: 2015-2016 Workload Apportionment Review
I'm afraid not. It's not rocket science but you need to do some coding.
You'll need to find a script (php) and save it to your local site folder. Then reference the script in your form's action attribute like so.
<form action="path/form-to-email-script.php" >
The input fields in your HTML form need to exactly match the script variables.
I'm assuming you're hosted on a Linux server which uses PHP code. Linux servers are also case sensitive, so upper case names are not the same as lower case names. It's usually best to use all lower case names in your form and script to avoid confusion.
Related Links:
Formm@ailer PHP from DB Masters
http://dbmasters.net/index.php?id=4
Tectite
http://www.tectite.com/formmailpage.php
If this is all a bit beyond your skill set, look at:
Wufoo.com (on-line form service)
http://wufoo.com/
Nancy O. -
How to generate unique numbers
hi all,
I want to generate unique numbers always starting from 1 using a single sql query and I dont want to use a sequence and i dont think rownum will be helpful for generating unique numbers in all cases . how to do this ?
thanks & regards,
kumar.If two users get the MAX from temp, they would be updating with the same value for two different rows.If TEMP is a genuine temporary table, this is not an issue, because the data in a temporary table is only visible within a session.
The big problem with this approach is the mutating table one: we cannot issue the requisite select statement from a BEFORE INSERT trigger. So this solution is only going to work with a view and an INSTEAD OF INSERT trigger.
Another, more workable, solution is to use a code control table. This can be (should be) another temporary table, with one row holding one column - next value for TEMP.ID. Normally we would rule out such a solution because it serializes access to the inserted table, but as this is only on a per session basis, it doesn't matter.
CREATE OR REPLACE TRIGGER tmp_bir BEFORE INSERT ON temp1 FOR EACH ROW
DECLARE
ln NUMBER;
BEGIN
SELECT nvl(code1.next_id,1) INTO ln
FROM code1;
:NEW.id := ln;
UPDATE code1
SET next_id := ln+1;
END;Beware: coded freehand, so may need debugging.
Cheers, APC -
Problem using SQL-LOADER and Unique Identifiers
I'm trying to load a fixed-length records file containing people names and phone numbers. Data is specified as follows
Toni Tomas66666666669999999999
Jose Luis 33333333330000000000
Notice that a maximum of 2 numbers can follow a person name, and 0000000000 means "no number specified".
I want to assign a unique identifier to people (instead of using the NAME field as a Primary Key) using an Oracle Sequence. I did that, but I don't know
how to assign the same id to each number.
Considering the 2 previous lines, desired result should be:
PEOPLE
======
1 Toni Tomas
2 Jose Luis
TEL_NUMBERS
===========
1 6666666666
1 9999999999
2 3333333333
In order to achieve that, my Control File looks like this
LOAD DATA
INFILE phonenumbers.txt
INTO TABLE people
personID "mySequenceName.nextval", --an Oracle sequence
name POSITION(1:10) CHAR
INTO TABLE tel_numbers
WHEN phonenumber !='0000000000'
personID !!!DON'T KNOW HOW TO REFERENCE THE SAME ID!!!!
phonenumber POSITION(11:20) CHAR
INTO TABLE tel_numbers
WHEN phonenumber !='0000000000'
personID !!!DON'T KNOW HOW TO REFERENCE THE SAME ID!!!!
phonenumber POSITION(21:30) CHAR
I tried lots of things, but anyone works:
a) reference the ID using something like ":\"people.personID\" (or similar aproaches)
b) using a BEFORE INSERT TRIGGER getting the CURRVAL value of the Sequence. This solution
does not work because it seems that all people is loaded before any telephone number. Hence,
all phone numbers are associated, wrongly, to the last person in the data file.
Does anyone know how can I solve this issue?
Help would be appreciated. Thank you.Hi V Garcia.
Information within the file is correct. Each line represents a COMPLETE record (Part of the line represents parent information and the rest is children data). As you can see in my first message, you can have more than one detail for a given master (i.e. two phone numbers):
Toni Tomas66666666669999999999
(10 chars for the name, 10 for each phone number. Thus, 2 children records to be created)
With the solution given by Sreekanth Reddy Bandi (use of CURRVALUE within the SQL-Loader Control File), not all the details are linked to the parent record on the DB tables. It seems SLQ-Loader gets crazy when there is such amount of information. -
All MonthNames and Month numbers in sql server
Hi All,
I want to display all months names and month numbers in a query.
like MName
Mno
January
1
February
2
March
3
December
12
Regards,
Mandava.Kudos to all the posts with fancier and higher-tech approaches. At the same time, this is a somewhat unique situation: Unlike most things, we'll always have just 12 months, and that will never change. This is an opportunity for "keep it
simple... Really simple", although the concept of using a VIEW for it is a little bit of lateral thinking.
I've also included two columns ("Mo" and "MMNum") that if you wanted to get technical, could be labeled "optional", and could also be computed instead of treated as literals. At the same time, the extra fields may someday be highly convenient and allow
you to NOT compute the text-equivalent ("01" of the integer "1") someday, so why not? Again, it's only 12 lines worth of typing, the data will never change, and sometimes, it's OK to use literals.
Create View MONTHLIST as
Select 1 as MM , 'January' as Mon , 'Jan' as Mo , '01' as MMNum
UNION
Select 2 as MM , 'February' as Mon , 'Feb' as Mo , '02' as MMNum
UNION
Select 3 as MM , 'March' as Mon , 'Mar' as Mo , '03' as MMNum
UNION
Select 4 as MM , 'April' as Mon , 'Apr' as Mo , '04' as MMNum
UNION
Select 5 as MM , 'May' as Mon , 'May' as Mo , '05' as MMNum
UNION
Select 6 as MM , 'June' as Mon , 'Jun' as Mo , '06' as MMNum
UNION
Select 7 as MM , 'July' as Mon , 'Jul' as Mo , '07' as MMNum
UNION
Select 8 as MM , 'August' as Mon , 'Aug' as Mo , '08' as MMNum
UNION
Select 9 as MM , 'September' as Mon, 'Sep' as Mo , '09' as MMNum
UNION
Select 10 as MM , 'October' as Mon , 'Oct' as Mo , '10' as MMNum
UNION
Select 11 as MM , 'November' as Mon , 'Nov' as Mo , '11' as MMNum
UNION
Select 12 as MM , 'December' as Mon , 'Dec' as Mo , '12' as MMNum
So, like everything else in SQL, there's always 50 ways to do something. This is another one. -
Pre Plus randomly erasing phone numbers
My Palm Pre Plus is randomly erasing phone numbers since I received it last Thursday. I suspect it has something to do with Synergy's syncing to my various accounts.
Example situation: Yesterday morning a friend texted me to see if I wanted to meet at a coffee shop. I told him yes, and we went and had coffee.
This morning, I went to text the same friend, only to find that his phone number was no longer listed under his contact profile. My only messaging option was through Google Talk (which I don't think counts) - even though my txt's from yesterday were still listed, had the little SMS marker - AND his phone number - next to them, in small grey font. But with no phone number, there was no SMS option.
I tried chatting with a Palm support person before leaving for coffee yesterday, who at first didn't believe that I had upgraded my phone to 1.4. They hadn't gotten the memo of its release yet. The situation was dropped with the hope that 1.4 had fixed the problem. It hasn't.
What's the deal here?
Also - I continue to have that infamous double type or missing letter problem with the keyboard.
In addition - does anyone else find it incredibly silly that virtually my entire contact list is impermanent? In other words, half of the information relies solely on my contacts maintaining their Facebook profiles and including their phone number and such. If a person's phone number has been pulled into my contacts from Facebook, and they decide to erase their Facebook account - boom - I no longer have their phone number. I suppose I could enter a duplicate phone number entry - but who has time? And with the above issue, how do I know it will even stay there?I have my Google account as my default profile, however most of my contacts were pulled in from Facebook and I manually entered phone numbers when necessary from my old Centro. I re-entered my friend's phone number and it has stuck around since last weekend, so hopefully as the other user above mentioned, it's just one of those things that happens early on and then sorts itself out.
I did a bit of testing today, to see how my phone was syncing to my google account, which was syncing back to Address Book on my Mac. If I delete a contact on my phone, or any part of a contact's information, it is erased from my google contacts on the next sync, and thus my Mac's address book on the computer's next sync. So now, all this information seems tied to me keeping my phone up to date. I wish it was just additive, not destructive.
I'm still somewhat upset over the apparent fact that my accounts are impermanent. I don't like the idea that I have no permanent record of a contact. If a friend is being pulled into my contacts from Facebook, and she has no other account associated with me, it seems that their existence in my address book is dependent on them maintaining their Facebook profile. I have no way to "lock it in" as it were. It doesn't seem that facebook-only contacts added into my Google contacts either. It's all a bit confusing.
I will have Verizon look into the keyboard issue. -
How do create a script that chooses a random swatch?
My idea is...instead of using math to create a random rgb number I want to choose specific color by hex or rgb and assign them a number 1-10 then use random() to choose a random number between 1-10 to choose one of those colors and place as foreground color. I just don't know javascript enough to create this script. Thank you
Does this help?
// 2014, use it at your own risk;
#target photoshop-70.032
// set up colors;
var theArray = [
[0,0,0],
[255,0,0],
[0,255,0],
[0,0,255],
[255,255,255],
// select color;
var thisColor = theArray[Math.floor(Math.random()*(theArray.length))];
// make forground color;
var theColor = new SolidColor();
theColor.rgb.red = thisColor[0];
theColor.rgb.green = thisColor[1];
theColor.rgb.blue = thisColor[2];
app.foregroundColor = theColor; -
Problems gifting playlist - order randomized and Error 1008
I can purchase music fine, so I know my account is indeed working.
But when I try to gift a playlist via the iTunes Store, 2 errors keep occuring:
1. Track order gets randomized. (Not that it'd matter, but I don't have shuffle checked.) Each time I try clicking the "Give Playlist" button, the list opens in the Store in a different random track order, numbered incorrectly. It's only an issue because these tracks need to play in order.
2. More important, I can't finalize the purchase. I get all the way to the last screen, after entering my password, but when I finally click "Buy Gift" I get this error popup:
"*We could not complete your iTunes Store request. An unknown error occurred (1008). There was an error in the iTunes Store.* Please try again later."
This has been happening all day -- even though I can purchase songs for myself just fine.
What should I do? This is time sensitive. I'm doing this through iTunes rather than burning a CD and giving it away because I feel strongly about paying for music. Bummer not to have any info on this.
Thanks for any help!Well at least we're not alone. I just sent a support request to Apple. Not sure if it makes any difference, but maybe if everyone does it'd be of use? http://www.apple.com/support/itunes/contact.html?form=el&topic=Express%20Lane%20 inquiry
BTW, does anyone know why the playlist order gets randomly changed when I try to gift a playlist? It's confounding, I keep having to cancel and try again until, randomly, the order is right -- which can take quite a while with 5 tracks! -
Is there any way to restore the addresses and phone numbers to the contacts on the iphone and computer that were erased after it synced?
Then chances are you won't be able to get them back. You can try restoring from your last iPhone backup to see if they're still there. To do this, prior to connecting your phone, open iTunes on your computer and go to Preferences; on the Devices tab check "Prevent...from syncing automatically". Then connect your phone to your computer and when it appears in iTunes on the left sidebar right-click on its name and choose Restore from Backup. Of course, if your backup has already been overwritten with a new backup that doesn't contain the missing contact information then this will not restore it to your phone.) When done you can go back to iTunes Preferences and re-enable automatic syncing if you prefer this.
-
I have synched my laptop with 4 albums on to my new iphone5. when I chose a song on the phone the library wizzes through all the song titles then chooses one random. Same happens on the laptop too. Genuis is off. Exhausted all avenues.
Many thanks.
With those symptoms, I'd try the following document:
Apple software on Windows: May see performance issues and blank iTunes Store
(If there's a SpeedBit LSP showing up in Autoruns, it's usually best to just uninstall your SpeedBit Video Accelerator.) -
Rename Lightroom 4.4 imported images with unique numbers?
I want to rename images imported from a card into Lightroom 4.4 with a single set of initials followed by a sequence of unique numbers. I would like the number sequence to continue from one import to the next. However, each time I start a new import, Lightroom starts again at 00001. Is there a way to instruct Lightroom to automatically continue the renumbering sequence from one import to the next WITHOUT manually resetting the "start" number each time?
What you described was my filenaming convention exactly, for a long while.
I constructed the unique numbers using:
shoot-name (enter number)
file-number (aka filename-number-suffix).
Pros: accomplishes the goal, and filenames are *very* short.
Cons: you have to manually manage job shoot number in case image-number rolls over.
If Lightroom supported folder number, then all would be well, since unique number would simply be:
{folder-number}{file-number}.
But, Lightroom doesn't (support folder number).
My new filenaming convention assures uniqueness using a combination of date-time and some other stuff:
{date}{photographer-initials}{time}{camera-designation}{image-number}.{extension}
Pros: supported by Lr native filenaming features (although I don't use Import dialog box for importing, nor native Lightroom for naming). And, alphabetical order is same as capture time order, except divvied by photographer (note: *not* divvied by camera photographer used, unless both were used during the same second).
Cons: *very* verbose, and not very readable.
So to answer your question more specifically: No: I'm not aware of any sequence number which accomplishes your goal exactly, but yes: there is a way without it.
Rob
Maybe you are looking for
-
Illustrator CS2 Quits on Startup
When I go to launch Illustrator it gets just past the initialization and then quits. I have tried reinstalling but no luck. Adobe no longer supports CS2...anyone have any ideas to try? This just started happening about a week ago, when I started my
-
Hello, Description; SunOS server4 5.10 Generic sun4u sparc SUNW I've pb with mcrypt librarie: 1. I've recently installed Apache, Mysql, Php successfully. 2. even for PhpMyAdmin but it requieres mcrypt librarie, 4. mcrypt has been downloaded & unzippe
-
Windows services for cluster monitoring
Hi there, I need a list of windows services I need to monitor in a 2-node w2008 r2 cluster such as ClusSvc
-
I wanted to know since the 3g iphone is going to be sold in Mexico can the old iphone also be used in mexico? My cousin wants my old iphone when i buy the new one. can he use it over there in Mexico?
-
Hi experts, for a customer request we have to write a toolbar script which opens a specific web page. Usual java libraries seem not to work in SAP Sourcing. This is the script which works fine in eclipse URI uriToken; try { uriToken = new URI(urlToke