Non-sequential shuffle.

Hey all, I seem to be a bit.. stuck. I'm trying to make a program that takes a user defined integer from the command line, then prints it out in a shuffled, non-sequential order. Meaning, 4 cannot follow 5, and 9 cannot follow 8, etc. Here is my code thus far:
     int N = Integer.parseInt(args[0]);
          int[] song = new int[N];
     for (int position = 0; position < N; position++) {
         int list = position;
         song[position] = list;
        for (int current = 0; current < N; current++) {
         int swap = current + (int) (Math.random() * (N - current));
         int tempSong = song[current];
         song[current] = song[swap];
         song[swap] = tempSong;
         if (song[current] == (song[swap+1] || song[swap-1]))
          { randomize song[swap]; }
         else
          { System.out.println(song[swap]); }
     System.out.println(song[current] + " ");
     }When I go to compile it, it gives me the following two errors:
Shuffle2.java:22: ']' expected
          { randomize song[swap]; }
                           ^
Shuffle2.java:22: illegal start of expression
          { randomize song[swap]; }
                               ^
2 errorsAny help with this would be greatly appreciated.

I'm really just not getting it. I wanna say I'm almost there, but at the same point I just don't know.
     int N = Integer.parseInt(args[0]);
     int[] song = new int[N];
     for (int position = 0; position < N; position++) {
         int list = position;
         song[position] = list;
        for (int current = 0; current < N; current++) {
         int swap = current + (int) (Math.random() * (N - current));
         int tempSong = song[current];
         song[current] = song[swap];
         song[swap] = tempSong;
         if (song[current] == song[swap+1] ||
          song[current] == song[swap-1])
         else
          { System.out.println(song[swap]); }
     System.out.println(song[current] + " ");
     }I'm just lost as to what I put where the "**" is.

Similar Messages

  • A way to add cross-dissolves to a bunch of different, non-sequential clips?

    Hey mac geniuses,
    Is there a way to add cross-dissolves to a bunch of non-sequential clips? Basically, one of my three video tracks features a different image for a few seconds every minute or so (they're slides from a presentation), and I'd like to be able to add a cross-dissolve at the beginning and end of each image.
    Is there a way to do those transitions all at once considering they're not back to back?
    Thanks for your help!
    BP

    Select the clips on the track with the track forward tool and press Cmd-T, assuming the current version.

  • Non-sequential enum causes error

    When calling a .NET object that has a property that sets an enum value, I am getting a runtime error in the .NET code if the enum is defined such that each value is not a sequential number (as in a bit mask). If the values are sequential there is no problem. In both cases, the sequence editor shows a drop down with the names of the enum values but puts the name in quotes.
    Does TestStand handle enums with non-sequential values properly?
    Solved!
    Go to Solution.

    It works for me if I specify the values separated by commas or specify the value numerically. For example:
        [Flags]
        public enum mybitfield
            myval1 = 0x1,
            myval2 = 0x2
    For the above bitfield, to specify both values for a parameter you can either specify:
    "myval1, myval2"
    0x1 | 0x2
    0x3
    Any of the above worked for me in both TestStand 4.2.1 and TestStand 2010.
    Hope this helps,
    -Doug

  • Non sequential values for knobs

    Is it possible to set non-sequential values for the control knobs on the front panel? For example, I'd like to set values of 1, 2, 5, 10, 20, 25, 50, 100, etc...

    Use the log mapping and text labels.  See example.
    Attachments:
    Non_Seq_Knob.ctl ‏5 KB

  • Generating non-sequential primary keys

    Is there a simple way to generate non-sequential primary keys? Say for instance I want to generate a user ID. I'd like all of the IDs to be unique, but not strictly sequential.

    >
    Hi Crottyan,
    Is there a simple way to generate non-sequential primary keys? Say
    for instance I want to generate a user ID. I'd like all of the IDs to be
    unique, but not strictly sequential.Normally this is done to eliminate contentation for index inserts - why do
    you want to do it?
    Be careful with GUID - it can be [url http://en.wikipedia.org/wiki/Globally_unique_identifier#Sequential_algorithms]sequential.
    It's a pity you didn't tell us your version of Oracle :( - you should always do this.
    10 XE has a sequential algorithm. 11 XE doesn't.
    HTH,
    [Edit] Just saw your post about inferring insert order - fair enough. Will be able to tell you about 11 EE next
    week ;)
    Paul...
    Edited by: Paulie on 18-Jul-2012 18:03

  • HSDIO Dynamic Generation of Digital Signals on Separate Non-sequential Ports Using the PCI-6542

    I am using the PCI-6542 trying to generate serial data timing on separate non-sequential ports 8, 9 and 16 as shown in the attached Digital Waveform Editor JPEG file
    I would like to be able to send binary data to ports (lines) 8, 9 and 16 without disturbing the other 29 ports on the PCI-6542 board. Looking on various HSDIO examples I don't see the capability of being able to send dynamic generation in binary format to a group of ports or being able to mask out non-timing involved ports like you can in static generation. 
    Was anyone successful in implementing this type of serial binary timing waveforms using the PCI-6542 board.
    Please advise.
    Thanks

    Hi Nycor,
    Outputting your data on lines that you specify is indeed possible on HSDIO cards.  You just need to list the channels you want to use in your Channel List when call the niHSDIO Assign Dynamic Channels VI.  For example, for lines 8, 9, and 16, you would input 8,9,16 into the Channel List.  Order in this list matters, so the first waveform in your file will correspond to line 8, second waveform to line 9, etc.  If your waveforms are out of order in your file, then rearrange the Channel List accordingly.
    One of my colleagues here is actually working on an example that implements this; I believe it may be for an open service request that you have.  I will speak with her when she is done and see if there is some example code we can provide that demonstrates this.  If you have further questions, I am happy to help out here, but you will likely get faster response through your open service request via phone and email.
    Regards,
    Chris E.
    Applications Engineer
    National Instruments
    http://www.ni.com/support

  • Non-sequential scanning with SCXI and Labwindows/CVI

    I'm trying to scan channels 0 and 2 (skipping channel 1) of a SCXI-1520 module with a SCXI-1000 chassis using LabWindows/CVI, but am getting error 10370 (Invalid Scan list).
    I've read here that the SCXI-1520 module supports non-sequential scanning, even with traditional NI-DAQ drivers, but I can't get this working.
    I'm using NI-DAQ 6.9.3 and LabWindows/CVI 6.0.
    I'm not using a channel string, but intead am using SCXI_Track_Hold_Setup and SCXI_SCAN_Setup.
    For the scan setup my arrays are:
    Module_List={1,1}
    #_of_Channels_List={1,1}
    Start_Channel_List={0,2}
    I've tried setting the Hol
    d_Count for the module to both 1 and 2 in SCXI_Track_Hold_Setup, but that doesn't help.
    Is this possible, and if so, how?

    OK, in essence, my code is:
    SCXI_Reset(chassis,-1);
    SCXI_Load_Config(chassis);
    hold_count=2; // Note: Tried 1 but that doesn't work either.
    SCXI_Track_Hold_Setup(chassis,slot,2,2,0,hold_count,device);
    // Note: tried 2,0,2 but doesn't work either, and then can't scan multiple modules.
    SCXI_Set_Gain(chassis,slot,-1,1);
    SCXI_Set_Excitation(chassis,slot,-1,VDC,5.0,&actual);
    SCXI_Configure_Filter(chassis,slot,0,BYPASS,0);
    SCXI_Configure_Filter(chassis,slot,2,BYPASS,0);
    SCXI_Configure_Connection(chassis,slot,-1,QUARTER);
    num_modules=2;
    Module_List={1,1};
    Channels_List={1,1};
    Start_List={0,2}
    SCXI_Scan_Setup(chassis,num_modules,Module_List,Channels_List,Start_List,device,0);
    // This causes error -10370:badScanListError
    Any help greatly appre
    ciated!

  • Editing to music track - possible to compile video non sequentially?

    Hello chaps.
    I'm creating a family skiing video, editing it tightly to a music track - someone falling over hits the beat, etc. You know the drill.
    I've run into one problem and I'm trying to work out if I'm missing something obvious, or whether it is a case of can't do that:
    What I would like to do.
    Rather that simply adding video sequentially from the beginning, there are certain clips that I know will fit well towards the end of the song. I'd like to place them there now. Continually editing from the front tends to lead to me using the best material at the beginning. Yes, I know I'm weak, but I'd like to place key anchor clips in first and then work around them with what's left.
    The problem
    iMovie 11 mutes the sound track after the end of the last piece of video in the project - so there's no obvious way to add video later on in the track.
    What I've tried.
    I've tried adding a single black clip that lasts the length of the track, but what I'd then like to do is be able to paste a clip to the playhead and have it replace that portion of the black clip. I can't quite work out how to do that, or if it is the correct approach. Placing the clip as a cut-away almosts works, but having the entire movie comprising cutaways is clearly silly.
    Am I missing something?
    Does anyone have any advice as to a better or correct approach?

    Bengt mentioned using dummy black photos (clips) as placeholders. Another option is to use the templates that are used in Trailers. These are located in the Map, Background & Animatic Browser (the last browser on the far right next to the Transition Browser). Apple calls these templates (or placeholders) "Animatics".
    The animatics can be placed along the timeline with varying durations. Later, when adding an actual clip, drag and drop it directly onto one of the animatics. Select Replace from the pop-up menu. If the duration of the actual clip differs from the animatic, the clip's duration will over-ride the animatic's duration. So, it will be a little tricky lining it all up.
    I haven't tried this personally, but it may work better than using Cutaways, but could be pretty tedious.
    Bengt's assumption regarding Final Cut Pro X is correct - it will handle this type of thing easily. As I understand it, you can insert an audio track, then position video in appropriate places along the timeline without gaps closing up.
    John

  • Quiz scoring incorrectly for non sequential questions

    Hi there!
    We are having some problems with a quiz scoring incorrectly.  We have a total of 17 quiz questions spread throughout a project.  There are 5 sequential questions at the end of the project.  When we preview the project, regardless of how you answer all 17 questions, only the 5 at the end are scoring. The review area indicates that the system knows there are 17 questions (i.e. 17 total question, 5 questions answered correctly) so it's recognizing them, just not scoring them correctly.  We're using version 5.0.1.624.  Any ideas?
    Thanks!

    Hello and welcome to the forum,
    First of all, please update your version, the latest version is 5.0.2.630  It is possible by the Help, Updates option.
    Could you check the Advanced interaction view/panel (F9)? It gives you an overview of all the scored objects, inc. question slides. Are all the question scores added to the Total score?
    Lilybiri

  • Permutations of non-sequential string in C

    Hi,
    I'm just learning C now and am trying to get my head around this permutation pickle I'm in.  I can pretty simply write code that will give all permutations of N number of letters from A-z.  E.g., if N = 4, it will print out AAAA AAAB .... zzzz. This is pretty simple iteratively or recursively with a counter.
    now, however, I want to enter in a string that does not neccessary contain letters in sequence, and find all the possible relevant permutations of that string.  E.g. I input a string of BEHP, and  I want to find all the permutations of this combination.  I don't want BBBB, BBBE, etc., I want BEHP, BHPE, BPHE, etc. 
    I think my current approach is severely limited by the counter method, as it's giving permutations that are just not relevant.
    Also, can someone please confirm the maths on this.  If I have a string of 3 letters, ABC, the number of possible combinations is 3! right? 3 factorial?
    Thanks

    I don't know C, but have a couple of logic-based suggestions.  I believe you are right in your permutations calculation of 3!.  To solve your problem of combinations, could you do something like put each character into an array (which is ordered by index) and then use a similar technique to the one you used for the other set of letters but base it on the index number?

  • Passing function parameters in a non-sequential fashon

    Consider the function below:
    function personal(Name:String,age:int,city:String):void
       trace(Name+" is "+age+ " years old and lives in "+city+ ".")
    The parameters can only(???) be passed in the order they are declared in the function as shown below.
    personal("John",40,"London"0)
    If the order is changed as: personal("London",John", 40), there will obviously be a type related error (position 2 parameter is an integer).
    Is there a way of passing function parameters as: personal(city="London",Name=John",age= 40)?
    That way one does not have to worry about the 'order' in which the parameters are passed.

    Micheal, I love such ELEGENCE.
    One more question, before I 'attempt' to go to bed!
    Below is code extracted from my main class definition.
    Notice how I 'populate' the artist object  before I pass it on as a parameter to my saveRecord function.
    It is rather clamsy, I think. Is there a better way of doing it?
    import ARTISTS
    var artist:ARTISTS = new ARTISTS;
    artist.ARTISTID = 123678;
    artist.FIRSTNAME = "Gordon";
    artist.LASTNAME = "Brown";
    artist.ADDRESS= "13 Darwin Street";
    artist.CITY= "London"
    saveRecord(artist);
    saveRecord(params:ARTISTS){
         //Some code here

  • Non-sequential IDs assigned using sequence="ID" on PrimaryKey

    Hello,
    I've seen some people asking something similar but I can't get this thing to work and it's driving me crazy. I'm using je-3.2.23 BTW.
    I have this simple class:
    * SYSADM.java
    * Created on 26 de junio de 2007, 09:29 AM
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package haven;
    import com.sleepycat.persist.model.Entity;
    import com.sleepycat.persist.model.PrimaryKey;
    * @author Mario
    @Entity
    public class SYSADM extends Usuario{
    private boolean root;
    @PrimaryKey(sequence="ID")
    private long id;
    /** Creates a new instance of SYSADM */
    public SYSADM() {
    /** Creates a new instance of SYSADM from parameters */
    public SYSADM(boolean root,long id, String loginName, String password, String nombre, String apellido, String email) {
    super(loginName, password, nombre, apellido, email);
    setRoot(root);
    //setId(id);
    /** Creates a new instance of SYSADM from a VOSYADM */
    public SYSADM(VOSYSADM voSYSADM) {
    super(voSYSADM.getLoginName(),voSYSADM.getPassword(),
    voSYSADM.getNombre(),voSYSADM.getApellido(),voSYSADM.getEmail());
    setRoot(voSYSADM.isRoot());
    //setId(voSYSADM.getId());
    public VOSYSADM getVOSYSADM() {
    return new VOSYSADM(this.isRoot(),this.getId(),this.getLoginName(),this.getPassword(),
    this.getNombre(),this.getApellido(),this.getEmail());
    public boolean isRoot() {
    return root;
    public void setRoot(boolean root) {
    this.root = root;
    public long getId() {
    return id;
    public void setId(long id) {
    this.id = id;
    and when I add records to the database using DPL I get ids like 1,101,201... and so on.
    I've looked at all the examples and tested them myself and I get the same behavior from all the classes I test.
    Plus all the tutorials and materials say that this is plain simple... let me quote from PrimaryIndex:
    " Employee employee;
    employee = new Employee("Jane Smith");
    primaryIndex.putNoReturn(employee); // Inserts an entity
    assert employee.id == 1;
    employee = new Employee("Joan Smith");
    primaryIndex.putNoReturn(employee); // Inserts an entity
    assert employee.id == 2; "
    I don't get... may be I'm plain dumb... should've ask that first to myself... I'm getting desperate here people... really!
    Anyway... any help is much appreciated.
    Regards to all,
    Mario

    First of all many thanks for your feedback... it's
    really encouraging in times of desperation to find
    somebody out willing and actually helping you! You're welcome!
    This is good. I'm aware of how RDBMS are integrated
    in the AS. Basically you need the driver and the
    connection to the database. For DBD JE I have made a
    simple test and I can persist objects from a web
    application in the AS. I simply open the environment
    that points to a directory in the file system. I
    suppose that as long as that directory is accessible
    through the network it should be fine. Is this
    correct?That''s correct. However, I strongly recommend that the Environment directory be on a local disk. There are problems with using NFS, see:
    http://www.oracle.com/technology/products/berkeley-db/faq/je_faq.html#1
    The question of scalability arises. As far as I read
    DBD C is the number one embeddable OpenSource
    Database out there. So I assume the same would apply
    for BDB JE some day (more even once it gets HA). How
    scalable is BDB JE? The limitation seems to be the
    available space in the machine where the filesystem
    is located? Does the filesystem have to the same
    where the AS is installed?It sounds like you're asking about data size scalability, not processor scalability. Yes, the limitation is the amount of file storage available, via a single directory, from the process that embeds JE. JE uses the standard java.io package for creating and accessing log files, so any hardware and file system that works under that API will work, as long as file locking is supported as mentioned in the FAQ above. JE creates numbered log files in sequence from 00000000.jdb to FFFFFFFF.jdb, and you can configure the size of the files. The default size is 10 MB.
    Ok I 'll look into it. Specialy into what a "Service"
    is. Off the top of my head I guess that by service
    you are referring to a stateless ejb implementing the
    Singleton pattern so you have only one instance
    running at all times, that embeds all database
    interactions, opens the environment at creation time,
    give data-accessors and thus handles all access to
    the database. Exactly.
    Should I open all indexes in the
    Singleton at creation time as well and simply get
    data-accessors to to perform read/write operations?Yes, that's what I recommend. See:
    http://www.oracle.com/technology/products/berkeley-db/faq/je_faq.html#12
    Ok we willhave to wait then. One of the questions I
    received about BDB JE is why a JE when you have the C
    version with a Java API? I guess it's related to
    being written in Java (portability-wise), it runs in
    the same JVM and it's 100% Java codeYes, this is the primary reason. A pure Java library is easier to deploy, test and debug than a C-based library, especially if you target multiple platforms. And the product can be optimized for the Java platform.
    and that it
    incorporates the DPL much in the way JPA works to
    have a closer integration. Am I correct?The DPL is only available for the JE product today, but it may be available for the C product in the future, since it is implemented on top of the base Java API that is common to both products.
    Also, while the JE product has similar functionality to the C product, it uses a different internal architecture. JE uses a log structured storage system rather than a traditional page-based storage system; this is better for writing (disk head moves less) but worse for fetching records that are not in cache (disk head moves more). JE also uses record locking rather than page locking; this improves concurrent access but uses more memory for locks.
    See "Berkeley DB Java Edition Architecture" here:
    http://www.oracle.com/technology/products/berkeley-db/je/index.html
    Last but not least. Portability-wise we are using DAO
    to persist and in the DAOs we perisist the objects.
    My logic is that by decorating POJOs with BDB JE
    annotations i can use DAO to persist in DB JE, any
    other persistency type including text, dbf, RDBMs
    using an ORM (without JPA), or creating a separate
    set of classes decorated with JPA annotations (though
    I would stick with ANSI SQL if I could). Do you see
    this as correct? Would you reccomend using DAO at all
    with Berkeley?Yes, a DAO is a good idea when you need to target multiple storage mechanisms. And the DPL does not meet this need, because it can only be used for Berkeley DB JE.
    If you need an API that works very well for Berkeley DB (JE and C products), plus relational DBs, then I strongly recommend Carbonado, an open-source framework from Amazon:
    http://carbonado.sourceforge.net/
    Mark

  • Trying to Create a non-sequential document

    I create a lot of front matter, chapter breaks and back matter for books this is then moved into prepress and merged with other content. We start with a book map and enter the pages we would need using the "start page numbering at" in the New Section dialogue box to force the pages into the correct page number position. For example I may have pages 1-7, 31-32, 63-64, 99-105. I think this could be scripted but I not sure where to begin. I think I could prompt for the page numbers, create a document with the largest page number, apply starting page numbers every page and delete all those that don't exist in the prompted array. Does this seem like the correct way? Does anyone have an idea of how this could be done or where to start? Thanks
    ~David

    Hi,
    As a short framework - I would start with dialogBox:
         edittext box for startNumber input
         edittext box for endNumber input
         listbox with existing masterSpreads to apply
         button for "Execute"
         button for "Stop"
    dialog is shown repeatly till "Stop" button is pressed
    each "Execute" action adds pages as a section from start... to endNumber
    Jarek

  • Excel Graph non-sequential Columns

    Hi all,
    I am trying to plot a graph in excel via Labview ActiveX components using say ColA as my x-axis data and Cols D and E as my y-axis data. My problem is that the Worksheet-Range method also includes the data of Cols B and C in the graph.  How could I omit plotting these unwanted columns?
    PS. I know this is easily done using the Report Generation Toolkit however this would limit me to <4000 rows/cols plots which is unwanted in my case..
    I have attached a zip file incl. a typical spreadsheet and my VI in case anybody wants to have a look.
    Thanks a lot,
    Harry
    Attachments:
    Sample.zip ‏819 KB

    Hi Peter,
    thanks for the tip. I had a more comprehensive check in the forum and found a very helpful topic here that pretty much provides the solution. In a way, the solution is similar to what you proposed. It appears that a "dummy" plot with as many series as required must be created first using consecutive columns. Then the "real" plot is created by overwriting the "dummy" plot via the series.collection class.
    I have added my VI in case anyone comes accross this challenge in the future. Must warn though that this VI looks pretty messy...
    Cheers,
    Harry
    Attachments:
    Excel_ActiveX_O2&NOx.vi ‏138 KB

  • Data Merge, non sequential

    I have a job which consists of 1200 records in an Excel .csv file. I have a 4 up template with I want the first page with csv file number 1, 401, 801 and 1200 for cutting purposes. Is there a way to do this, or would I be better looking at another option and if so, what option? Maybe an imposition software adon?
    Thanks a bunch for any help in advance..
    John

    No, you need to arange the data file in the correct order. It's pretty easy for a single field -- you just break out columns in the spread sheet  for each position on the merge template, then fill downwards until the correct number of rows is reached, which is one row per sheet in the stack, then fill the next column, and so forth. I don't see any reason why you can't do the same with multiple fields, in other words have a record with Stack1field1, stack1filed2, stack1field3 ... stack4field1, stack4field2, stack4field3. Then just drag the fields int the correct positions. Do a single record/page merge.

Maybe you are looking for