jeudi 22 septembre 2016

Trying to tilt multiple divs to different, random angles

I'm trying to achieve the opposite of what is described here.

I have a series of divs in a wordpress page, which I would like to appear on the page as each randomly tilted to a different slight degree.

They should also be straightened up as the user hovers on them.

Here's what I have:

    (function($) {
    $( document ).ready(function() {
        var a = Math.random() * 10 - 5;
        $('.format-aside').each(function( index ) { 
            $(this).css('transform', 'rotate(' + a + 'deg)');})
        });
})(jQuery);

at first, I skipped the .each part, but this resulted in all the divs being tilted the same way. However even with the .each they still end up tilted the same way.

As to the hover effect, I have set it in the CSS page:

.format-aside:hover{-ms-transform: rotate(0deg); 
-webkit-transform: rotate(0deg); 
transform: rotate(0deg);}

and it worked when all of this was done in CSS (but of course then all divs tilted the same way). Now it doesn't work anymore so I figure I should add the hover effect in jQuery?




mercredi 21 septembre 2016

python is there a built in way to return a list generator instead of list from random.sample

I use random.sample to sample from a very large range depending on the input load. Sometimes the sample itself is very large and since it is a list it occupies a lot of memory.

The application does not necessarily use all the value in the list. It would be great if random.sample can return a list generator instead of a list itself.

Right now I have a wrapper that divides the large input range into equal sized buckets and use randint to select a random number from each n / sample_size buckets.




Pick a random file from a directory in Java

I would like to pick a random file from any directory I want. such as C:\Users\Josh\Pictures\[randomFile]

I have no code to show I just would like to know how I would come by doing that.

What I am fully doing is using a class to change the background of my desktop, and now I want to add a random file to it so when it refreshes the background will be different and I wont have to stop the running code to manually change the name of the file in the path. If you are wondering heres what it looks like

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


public class BackgroundTest {

    final static File dir = new File("C:\\Users\\Kevin\\Pictures\\Pyimgur\\");
    static int size = 10;
    static String [] fileArray = new String[size];





public static void main(String[] args) {
    File[] files = dir.listFiles();
    for(int i =0; i<size;i++){
        int idz = (int)(Math.random()*size);
        fileArray[i]=files[idz].getName();

    }

    for(String x: fileArray){
        System.out.print(x);
    }

    String path = "C:\\Users\\Kevin\\Pictures\\Pyimgur\\";
    String picture = "picture.jpg";
    //System.out.print(fileArray[0]);

    SPI.INSTANCE.SystemParametersInfo(
            new UINT_PTR(SPI.SPI_SETDESKWALLPAPER),
            new UINT_PTR(0),
            path + picture,
            new UINT_PTR(SPI.SPIF_UPDATEINIFILE | SPI.SPIF_SENDWININICHANGE));
}

public interface SPI extends StdCallLibrary {

    //from MSDN article
    long SPI_SETDESKWALLPAPER = 20;
    long SPIF_UPDATEINIFILE = 0x01;
    long SPIF_SENDWININICHANGE = 0x02;

    SPI INSTANCE = (SPI) Native.loadLibrary("user32", SPI.class, new HashMap<Object, Object>() {
        {
            put(OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE);
            put(OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE);
        }
    });

    boolean SystemParametersInfo(
            UINT_PTR uiAction,
            UINT_PTR uiParam,
            String pvParam,
            UINT_PTR fWinIni
    );
    }
}




random generation of number (16 bit)

just a simple question What does it mean to produce rand. 100,000 16 bit unsigned integers? I don't understand the concept of 16 bits. I tried googling but did not help much.




PHP Array containing the names of all (but one) Folder in a Given Directory

So, I have a directory, called "images". Within that directory, I have a bunch of folders containing images. I would like a PHP array of the names of those folders.

One hiccup: I also have one "includes" folder in the directory which I don't want in the array.

If it helps, the folders I want all have the same "date_filenumber" ("YYYYMMDD_1234") naming patttern, which of course "includes" does not.

I plan to select one of the images at random to display on my landing page.

Please correct me if I'm wrong, but my understanding is that all I need is:

*PHP*

$array = [whatever gets me the list mentioned above]
$random = array_rand($array)


*HTML*

<img src="<?php echo 'images/'.$random.'0x.jpg';?>">

Thanks!




how to get next double on an open interval (x, y)

I know the basic algorithm for a range of numbers

double increment = min + (max - min) * rand.nextDouble();

This will give you a range on the interval [min, max) and that is because nextDouble includes 0 in the range. Is there a good way to exclude the minimum value from the range?




Random number generation and Arrays

I've been creating a random element generator of my first text adventure game, to be more specific, this:

    Random Generation = new Random();
    List<Integer> interact = new ArrayList<Integer>();
    for (int generator = Generation.nextInt(5) + 3; generator > 0; generator--) {
        interact.add(Generation.nextInt(3));
    };
    System.out.println(interact);`

Here, generator defines the amount of elements, and interact its a list that contains random numbers wich represent different interactive objects, the thing is, i need elements don't repeat, i've seen some previous questions, but i don't think they apply to my case, atleast completly.

I was thinking in a int a = Generation.nextInt(3); if (a != interact[]) {interact.add(a)} else {generator++}; but i dont know how to set an [any] in comparing arrays.

Also, as an extra (not my main question, so if it isn't possible i don't care too much) Can you set wich elements can be repeated and wich not, in a single generator? Or maybe a better random one, for this specific case? Thanks for reading to here.