vendredi 1 avril 2016

Random img src from array javascript

My current img source is static:

var img = new Image();
img.src = 'http://ift.tt/1N0qCqU';

How would i go about creating an array of sources and then it being picked randomly?

Creating an array is quite simple, im wondering about the random part and if theres any specifics when creating a source array




PHP Get one index and item of an array

I have the below function which will ask one of the questions of the array by random, and the answer must be sent to the database along with the index number of the asked question to be saved and used again on an event like password recovery etc...

My problem is I havent been able to find a method or option to use for getting both the index number and the question to be asked together.

I have tried the key, search_array and other ways but to no avail yet.

Please help

Thanks

 <?php
    function secQ(){
        $questions = array();
        $questions[0] = "first question";
        $questions[1] = "second question";
        $questions[2] = "third question";
        $questions[3] = "fourth question";
        $questions[4] = "fifth qestion";
        $questions[5] = "sixth question";
        $rand_keys = array_rand($questions, 2);
    }
    ?>




randomly insert list of chars into 2d array

I'm currently writing a word search game program however i've became stuck. I'm completely lost on how to insert random chars from a list into a 2D array I know usually you're supposed to use a nested for loop to do this but i have no idea how i can randomly insert the list in the const char's.

The programs output is currently a 16 by 16 square made from '.' to avoid confusing myself.

Any help or tips on how to insert the char's from my categories into the 2D array would be greatly appreciated. :)

Here is my code as it is at the moment;

char name[80];
char **create2DArray(); //function prototype
#define WIDTH 16
#define HEIGHT 16
char** myArray; //global array


int categorie;



int main(int argc, char** argv)
  {



    categoriesAnimals();
    categoriesFruits();
    categoriesCountries();
    myArray = create2DArray();
    system("PAUSE");
    return 0;
   }
  //----------------------------Categories----------------------------------

    categoriesAnimals(){
        const char *A[6];
        A[0] = "CAT";
        A[1] = "IGUANA";
        A[2] = "MOUSE";
        A[3] = "MONKEY";
        A[4] = "ORANGUNTAN";
        A[5] = "ZEBRA";
    }

    categoriesFruits(){
        const char *F[6];
        F[0] = "TOMATO";
        F[1] = "APPLE";
        F[2] = "ORANGE";
        F[3] = "KIWI";
        F[4] = "DRAGONFRUIT";
        F[5] = "DURIANS";

    }

    categoriesCountries(){
        const char  *C[6];
        C[0] = "COLUMBIA";
        C[1] = "GERMANY";
        C[2] = "MEXICO";
        C[3] = "AFGHANISTAN";
        C[4] = "ARGENTINA";
        C[5] = "HUNGARY";
    }



//-----------------------array ---------------------------------------------

        char **create2DArray()
    {
        int i,j;
        char **array = (char **) malloc(sizeof(char *) * WIDTH);

        for(i=0; i<WIDTH; i++)
        array[i] = (char *) malloc(sizeof(char) * HEIGHT);

        for(i=0; i<WIDTH; i++)
        for(j=0; j<HEIGHT; j++)

 // array[i][j] = 65 + rand() % 25;

        array[i][j] = '.';
    //--------prints array----------------------------------------          
        for(i=0; i<WIDTH; i++){
        for(j=0; j<HEIGHT; j++){
        printf("%c ", array[i][j]);
         }
        printf("\n");
        }   
        return array;
        }
    //------------------------------------------------------------  

//-----------------end of array --------------------------------------------    

//-----------------------------insert into 2d arrray------------------------   
for(i=0; i<WIDTH; i++){


        for(j=0; j<HEIGHT; j++){




How to generate 2 different random arrays of numbers using a C'tor in c++?

I am trying to create to different objects from the class 'NumSet'. NumSet Player1,player2; It generates 1 array properly - with random numbers. But the second one is copied just the same. The array of player one is equal to the array of player2. How to solve this ? Thanks.

NumSet::NumSet()
{
    srand(time(0));
    for (int i = 0; i < C_NUM; i++) {//Generate 2 random arrays.
        n_cards[i] = (rand() % 10) + 1;
    }
}

For example player1 will looks like that: {3,4,5,2,5} which is good (initialized with random numbers). The problem I dont know how to solve is that player2 will be exactly the same: {3,4,5,2,5}




Wordpress, random product only on home search page

I have a custom wordpress search page with page navigation numbers, my client asks me to random products on page 1 but not for others, but all products displayed randomly on home page should not displayed on others pages.

For the query i have this code :

$args = array(
  'post_type' => 'products',
  'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 )
)   

and for the random :

if( $args['paged'] == 1) {
    $args['orderby'] = 'rand';
} else {
    $args['order'] = 'DESC':
}

the results are there when i do a search, and first page random well, but some products that are already displayed on home page because of the random are also displayed on others pages (ex : page 2 ).

The aim is not display products that are already displayed on home page.

I already do something similar :

if( $page == 1 ) shuffle($r->posts);

But it shuffle only first the 10 products on page 1, and others products on others pages never display on page 1.

Sorry for bad english, and may you help me please ?

Thanks




Generating random data in python fitting given function

I want to generate data in python as if it was some experimental points. I want to get noisy exponential decrease, with noise and it's errors normally distributed. Like this picture, but exponential: noisy polynomial data. Will it be okay if I simply take exponential curve and add some Gaussian noise to it and also generate random errors like this

import numpy as np
errors = np.random.normal(0,1,100)

Or it can be done in a more intellectual way?




C++ adding float random numbers into array gives 0s

I'm trying to add random numbers into a float array, but the result is only 0z. Can anyone explain why is it so?

const int size = 100;
float aa[size];
for (int i = 0; i < size; i++)
    aa[i] = (float)rand();