Random generator (with weight)

Hey all..
I want to make a random generator, which will pick a random object from a vector.
Each object in the vector has been assigned a weighted INT value between 1 -> 100.
I want the generator to distribute the generated choices: to pick more values that have been set with a higher weight priority.
For every 10 choices I want 3 of them to have a weight above 70.
6 of them to have a weight between 40 -> 69
1 of them to be below 40.
Any advice or guidance would be greatly appreciated�
Cheers,
Gav.

Anyway, if you want what you said, I would have three
vectors rather than one. They would contain the items
with weight 70 and above, the items with weight 40 to
69, and the items with weight below 40. I would keep
track of how many requests had been made, and if that
number % 10 was 0, 1, or 2 I would choose from the
70-and-up vector, if it was 9 I would choose from the
below-40 vector, otherwise from the middle-weight
vector. The resulting sequence violates several common
randomness rules, I'm sure, but it does satisfy the
requirements.The forces the order to be that of 70+, 70+, 70+, mid, mid, mid, mid, mid, mid, 40-
That's not really random?
What I'd do is this:
Create a "class" list upon initialization (and after every 10 requests) that is a shuffled list of "classes." (Your classes being 70+, mid, and 40-). This list will contain the 10 requests and be randomly shuffled.
Then remove an item from that list first per random request and go and randomly choose a number in that "class".
When the "class" list is empty (after 10 requests) you'll go back to the top and re-create and shuffle it again for the next 10.
That should work and guarentee a better randomness. The only thing you have left to consider is how to pick a random number of said class. This shouldn't be too hard, I'd recommend storing each class in a separate bin and randomly choose from that bin.

Similar Messages

  • How to make a random generator with a max and a minimum

    hello
    can anybody telle me how to make a random generator for numbers with a maximum and minimum input
    thanks in advance

    Hi suske,
    If you want a random day for a given month, this is how I would do it.
    Hope this helps,
    -D
    Message Edited by Darren on 02-02-2006 01:35 PM
    Darren Nattinger, CLA
    LabVIEW Artisan and Nugget Penman
    Attachments:
    Days_per_month.jpg ‏32 KB

  • Random generated number along with barcode in smartforms

    Hi All,
    Is it possible to add some random generated number by system to add along with the end of the barcode in smartforms. (what could be the field) If so how it can be done. Tanks in advance
    Regards
    GK

    Hi Tankx man 4 the valuable reply,
         I am able to get that, but what my problem is,
    Eg: In my GR a item with 10 qty, so i made the qty as input and based upon that i am printing 10 labels. for ur ref the code is below"
    menge = TRUNC( is_mseg-menge ).
    DO menge TIMES.
    header-slno = header-slno + 1.
    APPEND header TO itab.
    the complete program is like as follows;
    menge = TRUNC( is_mseg-menge ).
    DO menge TIMES.
    header-slno = header-slno + 1.
    APPEND header TO itab.
    CALL FUNCTION 'QF05_RANDOM_INTEGER'
    EXPORTING
    RAN_INT_MAX   = '999999999'
    RAN_INT_MIN   = '100000000'
    IMPORTING
    RAN_INT       = RANINT
    EXCEPTIONS
    INVALID_INPUT = 1
    OTHERS        = 2.
    IF SY-SUBRC EQ 0.
    ENDIF.
    WRITE :/ RANINT.
    ENDDO.
    but in my barcode all the label has the same random number, can u say how to solve this.

  • How to generate random numbers with a known distribution of f(X)=(8X^2 + 1)*Exp( -X^2 )

    Dear All,
    I need to simulate a random number generator which can generate numbers X with the probability distribution of 
     f (X) = ( 8X^2 + 1)*Exp ( -X^2 ).
    This distribution is not a common distribution.
    I have searched a lot, but I still do not know how to realize it.
    Any help on this topic would be highly appreciated.

    Make a lookup table of the integral of your function (normalized to 1)
    Use the rectangle random generator and pipe that value through the lookup table, scale it ... voila.
    Greetings from Germany
    Henrik
    LV since v3.1
    “ground” is a convenient fantasy
    '˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'

  • Generating rectangles in random points with a random sizes. help please =)

    i want this to generate a lot of random rectangles in random points with different sizes all at once.
    so far i have this but it only generates one. it seems to me like it should do a lot but it doesnt. please help =)
    import javax.swing.*;
    import java.awt.*;
    import java.util.*;
    public class randomSquares{
      public static void main(String[] args) {
        randomSquares d = new randomSquares();
      public randomSquares(){
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MyComponent());
        frame.setSize(500,500);
        frame.setVisible(true); 
      public class MyComponent extends JComponent{
        public void paint(Graphics g){
          int height = 500;
          int width = 500;
         Random r = new Random();
         int number = r.nextInt();
         int random_number = number % 500; {
         if (random_number < 1) random_number = random_number + 500;
         System.out.println(random_number);
         for (int i = 0; i < 500; i++);{
              g.drawRect(random_number, random_number, random_number, random_number);
    }Edited by: javanub123 on Nov 13, 2009 7:27 PM

    javanub123 wrote:
    public class MyComponent extends JComponent{
    public void paint(Graphics g){Swing components should not override paint(Graphics) but instead paintComponent(Graphics).
    int height = 500;
    int width = 500;
         Random r = new Random();And a Random object should probably not be instantiated during either of those methods. It would be better to declare it as a class attribute and instantiate the Random object at time of construction.
    The Random class produces a series of numbers that is 'seeded' using the current time. If called in quick succession, it might produce identical series of numbers.
    Also, please use a single upper case letter at the start of each sentence. This helps the reader to quickly scan the text, looking for ways to help. You would not want to make it harder for someone to help, would you?

  • How to create a new user in IDM 8.1 with random generated password?

    Hi, i want create a new user using a modified tabbed user fom that cannot ask for password and confirm password to the administrator but randomly generate a new password (only when the form is opened in user creation) according to password policy and display it on the form.
    I think it is possible because Reset User Password Form does it, but i don't know how put this kind og logic in an other form.
    thanks
    Marco

    If you want to generate a users password randomly then you could take a look at the com.waveset.provision.PasswordGenerator class inside the Identity Mgr REF kit. Here's an example:
    <Rule name='generateRandomPassword'>
           <Comments>generate a random password</Comments>
           <RuleArgument name='accountId' value='Configurator'>
             <Comments>accountId of the user</Comments>
             <String>Configurator</String>
           </RuleArgument>
           <RunAsUser>
             <ObjectRef type='User' id='#ID#Configurator' name='Configurator'/>
           </RunAsUser>
           <block trace='true'>
             <defvar name='session'>
               <or>
                 <ref>context</ref>
                 <ref>display.session</ref>
               </or>
             </defvar>
             <defvar name='wsuser'>
               <invoke name='getObject' class='com.waveset.ui.FormUtil'>
                 <ref>session</ref>
                 <s>User</s>
                 <ref>accountId</ref>
               </invoke>
             </defvar>
              <defvar name='pwgenerator'>
               <new class='com.waveset.provision.PasswordGenerator'>
                 <ref>session</ref>
               </new>
             </defvar>
             <invoke name='generatePassword'>
               <ref>pwgenerator</ref>
               <ref>wsuser</ref>
             </invoke>
           </block>
        </Rule> You'll want to take the password.password field and inside the Default event handler check to see if waveset.id is null, if it is then call the Rule above.
    HTH,
    Paul

  • I am receiving numerous junk mail from random senders with names that appear to be random generated.  How can I stop it?

    The senders names appear to be random generated so I can't block one name.  I am getting 10 to 20 per day.  How vcan I stop it?

    You might try this program.
    SpamSieve

  • How to generate random objects with a click?

    Hi Guys,
    I am new to the forum so hello to you all!
    I start here with a question that doesn't leave me sleeping during the night.
    I am working on a interactive slideshow.
    That's all right, ultil now.
    Now things becomes blurry for me.
    In every page I would like to add a little animal in the lower right angle of the screen so, when u click on this animal, a baloon appears with a wroten sentence inside it.
    But, I wanto to make the sentences inside the baloon RANDOMLY different every time u click on the animal (using a selection, for example, of 30 sentences at all), but I don't really know what I have to do in order to realize my idea.
    I am not interested to create a preset cycle of sentences, but a random behavior with a click.
    any suggestion please?
    Thaks a lot and best regards!
    Theus

    As I imagined,
    I got some problems to do do that because I am new to the director use. So I can't made it working, if u cant be a little patient with me please, that's will be good!
    What I need is a more "steb by step" help if is not boring for you.
    I go to insert>control>field in order to create a field and then, after double ciking the field, I type four example sentences into the text editor that apperars, right?
    How I have to write the sentences inside the text editor in order to subdivide the text into first sentence, second sentences and so on? There is a special syntax to follow?
    I wrote these exaple sentences:
    "Triangle" "Square" "Circle" "Cube"..... As u see, I am not sure where and how I have to put the sentences in order to select them randomy
    About handlers.
    What I have to do to create an event handler?
    I created a button then i rename it ChooseRandomSentence but now I don't know what I need to do to proceed.
    Here have I to write this script?
    On ChooseRandomSentence
      global gSentenceList, gPreviousNR
      x = gSentenceList.count -- X = count sentences
      y =  random(x) -- Picks a random number from X
      repeat While y  =  gPreviousNR then -- check if number is used previous time player clicked button
          y =  random(x)
       end repeat
      put gSentenceList[y] into field "ShowSentence"  -- Shows random sentence in a field
      put y into gPreviousNR -- add number to next check
    end
    and this?
    on MouseUP
    ChooseRandomSentence
    end
    Some other questions:
    -What about letters X and Y into the exaples scripts u wrote? If I have 4 sentences, which numbers I need to use to replace X and Y?
    -I need to change sentences with  mouse clicking, and not simply moving the mouse over the sprite or the button, is MouseUP command a script about clicking or about moving over?
    As u see I am a very very beginner but I really want to learn, so hope I don't boring u with all those questions.
    Thanks again a lot
    and, If u came in Italy, there is a beer for you! cheers!!!
    Theus

  • Identity Sync - Password randomly generated in AD

    Configuration:
    DS 5.2 Patch 2
    on Solaris 9
    with Identity Sync for Windows 1 2004Q3
    configured to Synch from DS to AD
    I have set up object creation to flow from DS to AD, and the user creation works okay but the password I create the account with is not being pushed to AD. Instead it creates the account with a randomly generated password. Is there a way around this, I am attempting to script new user creations. Here is log entry I get in error.log when I create a user.
    [08/Mar/2005:11:35:59.416 +1000] WARNING 29 CNN101 tyr "Successfully created user cn=James Test,cn=users,dc=xxx,dc=xxx,dc=xx with randomly generated password. This account will be unusable until another password is set." (Action ID=CNN100-1027FA4BBD3-491, SN=2)
    Thankyou in advance for any assistance!!
    regards
    Gryph

    I've been doing some more testing and have some more information that might be important.
    I have been testing the attribute synchronisation for the mappings I have done, and noticed that if I modify the userpassword attribute in the DS console it is not being synch'd to AD, but I can modify other attributes and they do get synch'd. If I modify the password on the AD side it gets synch'd back to DS ok. I have attribute modification set to flow in both directions and the password mapping is (DS) userpassword <--> unicodepwd (AD).
    Given it seems to ignore changes to the userpassword attribute for modifications, it looks like this is also holding true for creations, and I guess this is why it's randomly assigning a password.
    Any ideas why it sees other attribute modifcations and synch's them from the DS side, but is not seeing the userpassword attribute?
    Regards
    Gryph

  • How to use the random generator in java

    hey peeps, this is the class in which i am trying to implement the random generator in;
    public class Matchlist
        private studentdetails sd = new studentdetails();
        /** matchList StringBuilder stores the match list in progress */
        private StringBuilder matchList = new StringBuilder();
        private int loop = 0;
        private int matches = 0;
        public Matchlist()
            sd.createstudentdetails();
        /** Method to create the actual match list, returns the list as a string */
        public String CreateMatch()
            int g;
            int y;
                for (g = 0; g < 4; g++)//g = game
                    for (y = 17; y > -1; y--)//y = green house
                        /** Check to see if the game is empty */
                        if (sd.getgh(y).getGame(g).equalsIgnoreCase(""))
                            for (int x = 0; x < 18; x++) //x = yellow house
                                if (sd.getyh(x).getGame(g).equalsIgnoreCase(""))
                                    if (sd.getgh(y).getC_lass() != sd.getyh(x).getC_lass())
                                        /** Check to see if the person has played the other person */
                                        if (sd.getgh(y).checkPlayed(sd.getyh(x).getName()) == false)
                                            /** Set the game to the name of the opponent played */
                                            sd.getyh(x).changeGame(g, sd.getgh(y).getName());
                                            sd.getgh(y).changeGame(g, sd.getyh(x).getName());
                                            /** Build the match list step by step using append with \n at the end to create a new line */
                                            matchList.append(sd.getyh(x).getName() + " vs " + sd.getgh(y).getName() + "\n");
                                            matches++;
                                            break;
                /** Convert the stringbuilder into an actual string, then return it */
                String completeMatchList = matchList.toString();
                System.out.println(matches);
                for (int i = 0; i <18; i++)
                    sd.getyh(i).getEmptyMatches();
                    sd.getgh(i).getEmptyMatches();
                return completeMatchList;
        }what i dont understand is how to implement it to pick my matches at random using the http://java.sun.com/j2se/1.4.2/docs/api/java/util/Random.html java tutorials from here
    regards

    How to use Random ?
    First you open API then you read it, then you use it.
    You mention you try to use it but i just see a horrible nested for for for if if if loop.
    Restructure code and question and maybe it makes more sense.
    Edited by: pgeuens on 10-mrt-2008 22:58

  • Writing a class using random generator in bluej

    Hello
    Im trying to write a class for a deck of cards. Im using a random generator but I dont know how to write the instance variable.
    I have to make 4 suits heart, club, spade, dimonds. and 13 for face value. I know how to random generate numbers. Like if I were making a slot machine to give me 3 numbers in a rage from 0-10. Thats just numbers. How do I random generate values of 1-13 and have it output a random suit? Also how do I make it say if its a jack king or queen? Do I need a constructor or how would I make the card with the face value of 13 suit heart and the card be a queen.
    before jumping down my throat about this being a homework assignment...yes it is but this step Im seeking help on there is no example for this type of generating.
    Thanks for any help
    Rewind

    Well, this is far from bullet-proof, but I think gets the basic idea across. This does sampling with replacement; if you wanted to do something like shuffle a deck of cards you'll need a smarter approach than this.
    import java.util.*;
    public class RandomCards {
      public static void main(String[] args) {
        Suit suit=new Suit();
        for (int i=0; i < 10; i++) {
          System.out.println(suit.nextSuit());
      private static class Suit {
        public static final String HEART="Heart";
        public static final String DIAMOND="Diamond";
        public static final String SPADE="Spade";
        public static final String CLUB="Club";
        private final String[] SUITS={ HEART, DIAMOND, SPADE, CLUB };
        private Gen suitGen=new Gen(0,3);
        public String nextSuit() {
          return SUITS[suitGen.nextInt()];
      private static class Gen {
        private int floor,ceiling;
        private Random rand;
        public Gen(int floor, int ceiling) {
          this.floor=floor;
          this.ceiling=ceiling;
          rand=new Random();
        public int nextInt() {
          return rand.nextInt(ceiling-floor)+floor;

  • Random numbers with leading zeros

    Hi,
    I want to generate random numbers with leading zeros.
    My code so far:
    import java.util.Random;
      Random r = new Random();
      int randInt = r.nextInt(100);My aimed output is something like:
    0012 or 0123 ...
    Thanks
    Jonny

    Hi,
    sorry for not getting it with NumberFormat. I used DecmailFormat instead:
    DecimalFormat df = new DecimalFormat("0000");
    df.setMinimumIntegerDigits(4);
    df.format(r.nextInt(40)));This gave me the right output, like 0013 or 0123 ...
    Thanks
    Jonny

  • SPro | SQR APY1060 is randomly generating Corrupted PDF's

    Hi,
    We're in the process of implementing SPro FSCM 8.9 on 8.47.11 for one of our clients. While the running the OOB SQR APY1060, we've found that the SQR randomly generates corrupted PDF. When we run the Process again, it works fine...Its is also difficult to replicate in other environments.
    Has any body faced an issues like this earlier with any PS delivered SQR.
    We've been able to zero in on the culprit - Control-M ... We've noticed a pattern, using the same run control ID, if we run it (PSJob) using the online page, then the PSJob runs absolutely fine. However, when we schedule it through Control-M the corruption happens. Also, if we create separate Process Requests in Control-M to schedule individual processes rather than the OOB PSJob, the SQR runs fine...Not sure if some one has come across such an issue...
    Thank You
    Prashant
    Edited by: PSFT_PP on Feb 9, 2009 8:47 AM

    I am not sure about this..but do you have different run control for the different OS or the same run control. Unix always recognises CAPS runcontrol values. do a check on that please.

  • Randomly generate an ID for SQL Create Table command

    Hi,
    I need help to randomly generate an integer, which i can use as a primary key for the ID of a table field. I have no idea how to do this so that it generates a different number every single time.
    Right now it just increments the ID by 1. Maybe, is there a way to get the last ID value of the table field and then increment starting from that one? thanks

    Your analysis is flawed! One of my main reasons for
    doing this is to reduce the load on the db server. I
    don't have to go to the db to get an id every time I
    need one. Every now and again (usually less than one
    in a 2000) I have to repeat an insert operation.
    You already stated that this was the reason, so I used that as part of my assessment. With most, perhaps all databases, the ability to increment a key is done as part of the insert operation. It requires no additional 'trip' to the database to get the ID. There is so much wrong with your idea, I hardly know where to start. I wouldn't be so firm except you stated that you do this all the time. Even using it once is very questionable I wouldn't want this idea to profilerate to other peoples systems without comment.
    You also said:
    On one project I was having to place usage transaction records
    into a database with each one needing an ID. I started using your
    technique but it was taking almost as much time as the insert of
    each transaction into the database.I agree, and I think dcminter agreed that there are less expensive practices then max(fld)+1 which are in fact using the vendor specific capabilities. However, if this was taking as long as your insert, there was probably something else wrong. For example, if the field you are getting the max value for isn't indexed, or isn't the first field in a contatenated index (an index of multiple fields), then some databases (there are exceptions like redbrick) will require either a full table scan, an index scan or an ackward index lookup to give back the max value. It shouldn't be that way, but it is and you have undestand how your database is resolving max() in order to make the best decisions.
    I stand by analysis and I would suggest that rather then use your method "all the time" that you save it for that unusual situation where nothing else will work for you.

  • QCPatch 'Random Generator' Broken Seed?

    Hi there all,
    Just putting this out there - perhaps I'm wrong, but want some other QC developers who are more experienced to compare with.
    Quartz Composer Patch "Random Generator" - one of the inbuilt patches available.
    Its purpose is to generate random numbers between a range, and supply the number on its output port.
    To this end, it works fine.
    My problem with this patches behavior occurs when it is nested in a macro patch, and that patch is then duplicated (purpose obvious).
    *The duplicated macro patch appears to also copy the Random Generators' base seed.*
    For example I have the same picture resulting from Random Generators nested inside a macro patch that contains processing for a random choice of image to a sprite.
    The only way i could work around this (and this may help others with the same problem) was to Publish the Input ports all the way up to the root level patch, and supply new instances of a Random Generator for each instance of the duplicated macro patch.
    Then I received fresh random seeds from the generator and different images were selected for output to my nested sprite.
    Awfully inconvenient given that each macro had 4 levels of nesting using objects like render in image, 3D transformation and Lighting - all patches that require nesting, and also reset your ports being passed to a parent, meaning you have to - 're-map' the Published Inputs with every layer of nesting. Not to mention the fact that the root level of the document is cluttered all to **** with millions of Random Generator patches.
    Anyone get this behavior?
    Please let me know if I'm just screwing my design up, or if this is encountered by you too and we should report it as a bug. (Ive only been devving QC for several weeks straight, so I'm want to actually report it as a bug yet).
    Many thanks in advance,
    Wilks.

    A random created with the same seed will give the same set of random numbers.
    Take out the Random creation from the loop
    try
                 BufferedWriter out = new BufferedWriter(new FileWriter("c:/test.txt"));
                    //Create Random here.
                     Random r = new Random( );//No need for any seed
                 for (int i = 0; i < 1000; i++)
                      out.write(String.valueOf(r.nextInt(9)));
                 out.close();
    catch (IOException e)
    [url http://www.feedfeeds.com/feedtv]Feed Your Feeds

Maybe you are looking for

  • IPod Touch not being recognized by Windows 7.

    So I have a little problem, my USB cable will charge if I use the wall charger but when I try to connect it to my PC it doesn't.I can't seem to make it appear on iTunes either.Tried using the troubleshooter with no succes tough,

  • How do I receive a refund on the 55.0 GB that I purchase within 15 days.

    How do I receive a refund on icloud storage that I purchased within the 15 days window of cancellation?

  • Illustrator cc 2014 crash when startup in Mac 10.9.3

    Trying to start cc 2014 after installed. (in Mac 10.9.3) but crashed.         Crashed Thread:  0  Dispatch queue: com.apple.main-thread tried to move out third party plug in as mention by adobe help blow but still not working. Solution In the Finder,

  • Program not compiling giving Error : Invalid path, "C:\Program Files\Java--

    I am using jcreator where i am getting this error while compiling Error : Invalid path, "C:\Program Files\Java\j2re1.4.2_05\bin\javac.exe" -classpath "C:\Program Files\Xinox Software\JCreatorV3LE\MyProjects\zeroCode\classes" -d C:\Program" Files\Xino

  • SAP Enterprise Support

    Hi experts, For Enterprise Support, I'm sure that I need to install the addon ST-ETP and to implement the initial setting described the notes [1140258|http://service.sap.com/sap/support/notes/1140258], [1109650|http://service.sap.com/sap/support/note