hw/hw1/synthesizer/GuitarString.java
public void pluck() {
        // TODO: Dequeue everything in the buffer, and replace it with random numbers
        //       between -0.5 and 0.5. You can get such a number by using:
        //       double r = Math.random() - 0.5;
        //
        //       Make sure that your random numbers are different from each other.

        // Make sure that random numbers are different from each other.
        double[] r = new double[buffer.capacity()];
        r[0] = Math.random() - 0.5;
        // System.out.println(r[0]);  // Test

        double random;

        for (int i = 1; i < r.length; i += 1) {
            random = Math.random() - 0.5;

            while (Arrays.asList(r).contains(random)) {
                random = Math.random() - 0.5;
            }
            r[i] = random;
            // System.out.println(r[i]);  // Test
        }

        // Dequeue everything in the buffer
        for (int i = 0; i < buffer.capacity(); i += 1) {
            buffer.dequeue();
        }

        // System.out.println(buffer.isEmpty());

        // Replace it with random numbers
        for (int i = 0; i < buffer.capacity(); i += 1) {
            buffer.enqueue(r[i]);
        }

    }
/* Pluck the guitar string by replacing the buffer with white noise. */
Pluck the guitar string by replacing the buffer with white noise.
Pluck the guitar string by replacing the buffer with white noise .
public void pluck() {
               Make sure that your random numbers are different from each other.
         Make sure that random numbers are different from each other.
        double[] r = new double[buffer.capacity()];
        r[0] = Math.random() - 0.5;
         System.out.println(r[0]);   Test
        double random;
        for (int i = 1; i < r.length; i += 1) {
            random = Math.random() - 0.5;
            while (Arrays.asList(r).contains(random)) {
                random = Math.random() - 0.5;
            }
            r[i] = random;
             System.out.println(r[i]);   Test
        }
         Dequeue everything in the buffer
        for (int i = 0; i < buffer.capacity(); i += 1) {
            buffer.dequeue();
        }
         System.out.println(buffer.isEmpty());
         Replace it with random numbers
        for (int i = 0; i < buffer.capacity(); i += 1) {
            buffer.enqueue(r[i]);
        }
    }
public void pluck ( ) { double [ ] r = new double [ buffer . capacity ( ) ] ; r [ 0 ] = Math . random ( ) - 0.5 ; double random ; for ( int i = 1 ; i < r . length ; i += 1 ) { random = Math . random ( ) - 0.5 ; while ( Arrays . asList ( r ) . contains ( random ) ) { random = Math . random ( ) - 0.5 ; } r [ i ] = random ; } for ( int i = 0 ; i < buffer . capacity ( ) ; i += 1 ) { buffer . dequeue ( ) ; } for ( int i = 0 ; i < buffer . capacity ( ) ; i += 1 ) { buffer . enqueue ( r [ i ] ) ; } }
Pluck the guitar string by replacing the buffer with white noise.
Pluck the guitar string by replacing the buffer with white noise .
// TODO: Dequeue everything in the buffer, and replace it with random numbers //       between -0.5 and 0.5. You can get such a number by using: //       double r = Math.random() - 0.5; // //       Make sure that your random numbers are different from each other. // Make sure that random numbers are different from each other. // System.out.println(r[0]);  // Test // System.out.println(r[i]);  // Test // Dequeue everything in the buffer // System.out.println(buffer.isEmpty()); // Replace it with random numbers