lundi 28 mars 2016

Random Number with NextDouble (C#)

I'm programming a perceptron and really need to get the range from the normal NextDouble (0, 1) to (-0.5, 0.5). Problem is, I'm using an array and I'm not sure whether it is possible. Hopefully that's enough information.

Random rdm = new Random();

double[] weights = {rdm.NextDouble(), rdm.NextDouble(), rdm.NextDouble()};




how is /dev/random data generated on unix systems?

I would like to know how this data is generated. Is the data pulled from processor registers, random memory locations, or signal noise?




In java how can i randomize and int in an array

Hi i am just learning java and want to write a sort of vocabulary trainer. It is working but i want to give the questions in a random order. The trainer pics a list from an external file and splits the file in two parts. It is asking as long the next line isn't null.

for (int i = 0; (zeile = br.readLine()) != null; i++) { 
        splitted = zeile.split(";");                     
        eng[i] = splitted[0];                          
        ger[i] = splitted[1];

then i am asking for the vocabulary. But as you can see its always in the same order. I don't know how i can correctly randomize the list before the asking part.

for (int j = 0; j < eng.length; j++) {

        correct = false;
        while (!correct) {

            System.out.print(eng[j] + " bedeutet: ");

            gerEingabe = vokabel.nextLine(); 

            if (gerEingabe.equals(ger[j])) {
                System.out.println("Das ist Korrekt. Auf zur nächsten Aufgabe.");
                correct = true;
            } else {
                System.out.println("Das war leider Falsch. Bitte versuche es noch ein mal.");

It would be nice if someone can help me with this.




Prioritizing first items in a list (Random & Probability Distribution)

I have a list of sorted elements. First elements are supposed to be prioritized in contrast to last elements. Currently, I am just using random.choice(foo) to select items from my list.

The algorithm I am writing would be a lot more efficient with a different probability distribution (described above). Unfortunately, I am not sure how to implement it




Massive Python random sharer

I tried to make a program to take a certain amount of elements and randomly generate them. For example, the user could enter twenty names and have the algorithm spit them out randomly. I built the program in such a way that you could enter up to twenty elements, and it would print out that number plus one random things. So you could enter twenty elements and it would randomly choose from them twenty-one times. The problem is I'm not all too experience with random, so I made it ridiculously large (just shy of 500 lines). It works, but I'd like: 1) For it to be shortened. 2) To take any number, rather than between 2 and 20 and 3) To be able to spit out a user-entered number of random items. I don't know if any of that made sense, but help if you can! The whole massive code:

import random
a = input('Enter a number of elements(maximum twenty).\n')
if a < 2 or a > 20:
    print('Restart program and enter a value between two and twenty.')
if(a == 2):
    one = raw_input('Enter the first element.\n')
    two = raw_input('Enter the second element.\n')
    list_one = [one,two]
    choice_one = random.choice(list_one)
    choice_two = random.choice(list_one)
    choice_three = random.choice(list_one)
    print(choice_one, choice_two, choice_three)
if(a == 3):
    one = raw_input('Enter the first element.\n')
    two = raw_input('Enter the second element.\n')
    three = raw_input('Enter the third element.\n')
    list_one = [one,two,three]
    choice_one = random.choice(list_one)
    choice_two = random.choice(list_one)
    choice_three = random.choice(list_one)
    choice_four = random.choice(list_one)
    print(choice_one, choice_two, choice_three, choice_four)
if(a == 4):
    one = raw_input('Enter the first element.\n')
    two = raw_input('Enter the second element.\n')
    three = raw_input('Enter the third element.\n')
    four = raw_input('Enter the fourth element.\n')
    list_one = [one,two,three,four]
    choice_one = random.choice(list_one)
    choice_two = random.choice(list_one)
    choice_three = random.choice(list_one)
    choice_four = random.choice(list_one)
    choice_five = random.choice(list_one)
    print(choice_one, choice_two, choice_three, choice_four, choice_five)
if(a == 5):
    one = raw_input('Enter the first element.\n')
    two = raw_input('Enter the second element.\n')
    three = raw_input('Enter the third element.\n')
    four = raw_input('Enter the fourth element.\n')
    five = raw_input('Enter the fifth element.\n')
    list_one = [one,two,three,four,five]
    choice_one = random.choice(list_one)
    choice_two = random.choice(list_one)
    choice_three = random.choice(list_one)
    choice_four = random.choice(list_one)
    choice_five = random.choice(list_one)
    choice_six = random.choice(list_one)
    print(choice_one, choice_two, choice_three, choice_four, choice_five, choice_six)
if(a == 6):
    one = raw_input('Enter the first element.\n')
    two = raw_input('Enter the second element.\n')
    three = raw_input('Enter the third element.\n')
    four = raw_input('Enter the fourth element.\n')
    five = raw_input('Enter the fifth element.\n')
    six = raw_input('Enter the sixth element.\n')
    list_one = [one,two,three,four,five,six]
    choice_one = random.choice(list_one)
    choice_two = random.choice(list_one)
    choice_three = random.choice(list_one)
    choice_four = random.choice(list_one)
    choice_five = random.choice(list_one)
    choice_six = random.choice(list_one)
    choice_seven = random.choice(list_one)
    print(choice_one, choice_two, choice_three, choice_four, choice_five, choice_six, choice_seven)
if(a == 7):
    one = raw_input('Enter the first element.\n')
    two = raw_input('Enter the second element.\n')
    three = raw_input('Enter the third element.\n')
    four = raw_input('Enter the fourth element.\n')
    five = raw_input('Enter the fifth element.\n')
    six = raw_input('Enter the sixth element.\n')
    seven = raw_input('Enter the seventh element.\n')
    list_one = [one,two,three,four,five,six,seven]
    choice_one = random.choice(list_one)
    choice_two = random.choice(list_one)
    choice_three = random.choice(list_one)
    choice_four = random.choice(list_one)
    choice_five = random.choice(list_one)
    choice_six = random.choice(list_one)
    choice_seven = random.choice(list_one)
    choice_eight = random.choice(list_one)
    print(choice_one, choice_two, choice_three, choice_four, choice_five, choice_six, choice_seven, choice_eight)
if(a == 8):
    one = raw_input('Enter the first element.\n')
    two = raw_input('Enter the second element.\n')
    three = raw_input('Enter the third element.\n')
    four = raw_input('Enter the fourth element.\n')
    five = raw_input('Enter the fifth element.\n')
    six = raw_input('Enter the sixth element.\n')
    seven = raw_input('Enter the seventh element.\n')
    eight = raw_input('Enter the eighth element.\n')
    list_one = [one,two,three,four,five,six,seven,eight,]
    choice_one = random.choice(list_one)
    choice_two = random.choice(list_one)
    choice_three = random.choice(list_one)
    choice_four = random.choice(list_one)
    choice_five = random.choice(list_one)
    choice_six = random.choice(list_one)
    choice_seven = random.choice(list_one)
    choice_eight = random.choice(list_one)
    choice_nine = random.choice(list_one)
    print(choice_one, choice_two, choice_three, choice_four, choice_five, choice_six, choice_seven, choice_eight, choice_nine)
if(a == 9):
    one = raw_input('Enter the first element.\n')
    two = raw_input('Enter the second element.\n')
    three = raw_input('Enter the third element.\n')
    four = raw_input('Enter the fourth element.\n')
    five = raw_input('Enter the fifth element.\n')
    six = raw_input('Enter the sixth element.\n')
    seven = raw_input('Enter the seventh element.\n')
    eight = raw_input('Enter the eighth element.\n')
    nine = raw_input('Enter the ninth element.\n')
    list_one = [one,two,three,four,five,six,seven,eight,nine]
    choice_one = random.choice(list_one)
    choice_two = random.choice(list_one)
    choice_three = random.choice(list_one)
    choice_four = random.choice(list_one)
    choice_five = random.choice(list_one)
    choice_six = random.choice(list_one)
    choice_seven = random.choice(list_one)
    choice_eight = random.choice(list_one)
    choice_nine = random.choice(list_one)
    choice_ten = random.choice(list_one)
    print(choice_one, choice_two, choice_three, choice_four, choice_five, choice_six, choice_seven, choice_eight, choice_nine, choice_ten)
if(a == 10):
    one = raw_input('Enter the first element.\n')
    two = raw_input('Enter the second element.\n')
    three = raw_input('Enter the third element.\n')
    four = raw_input('Enter the fourth element.\n')
    five = raw_input('Enter the fifth element.\n')
    six = raw_input('Enter the sixth element.\n')
    seven = raw_input('Enter the seventh element.\n')
    eight = raw_input('Enter the eighth element.\n')
    nine = raw_input('Enter the ninth element.\n')
    ten = raw_input('Enter the tenth element.\n')
    list_one = [one,two,three,four,five,six,seven,eight,nine,ten]
    choice_one = random.choice(list_one)
    choice_two = random.choice(list_one)
    choice_three = random.choice(list_one)
    choice_four = random.choice(list_one)
    choice_five = random.choice(list_one)
    choice_six = random.choice(list_one)
    choice_seven = random.choice(list_one)
    choice_eight = random.choice(list_one)
    choice_nine = random.choice(list_one)
    choice_ten = random.choice(list_one)
    choice_eleven = random.choice(list_one)
    print(choice_one, choice_two, choice_three, choice_four, choice_five, choice_six, choice_seven, choice_eight, choice_nine, choice_ten, choice_eleven)
if(a == 11):
    one = raw_input('Enter the first element.\n')
    two = raw_input('Enter the second element.\n')
    three = raw_input('Enter the third element.\n')
    four = raw_input('Enter the fourth element.\n')
    five = raw_input('Enter the fifth element.\n')
    six = raw_input('Enter the sixth element.\n')
    seven = raw_input('Enter the seventh element.\n')
    eight = raw_input('Enter the eighth element.\n')
    nine = raw_input('Enter the ninth element.\n')
    ten = raw_input('Enter the tenth element.\n')
    eleven = raw_input('Enter the eleventh element.\n')
    list_one = [one,two,three,four,five,six,seven,eight,nine,ten,eleven]
    choice_one = random.choice(list_one)
    choice_two = random.choice(list_one)
    choice_three = random.choice(list_one)
    choice_four = random.choice(list_one)
    choice_five = random.choice(list_one)
    choice_six = random.choice(list_one)
    choice_seven = random.choice(list_one)
    choice_eight = random.choice(list_one)
    choice_nine = random.choice(list_one)
    choice_ten = random.choice(list_one)
    choice_eleven = random.choice(list_one)
    choice_twelve = random.choice(list_one)
    print(choice_one, choice_two, choice_three, choice_four, choice_five, choice_six, choice_seven, choice_eight, choice_nine, choice_ten, choice_eleven, choice_twelve)
if(a == 12):
    one = raw_input('Enter the first element.\n')
    two = raw_input('Enter the second element.\n')
    three = raw_input('Enter the third element.\n')
    four = raw_input('Enter the fourth element.\n')
    five = raw_input('Enter the fifth element.\n')
    six = raw_input('Enter the sixth element.\n')
    seven = raw_input('Enter the seventh element.\n')
    eight = raw_input('Enter the eighth element.\n')
    nine = raw_input('Enter the ninth element.\n')
    ten = raw_input('Enter the tenth element.\n')
    eleven = raw_input('Enter the eleventh element.\n')
    twelve = raw_input('Enter the twelth element.\n')
    list_one = [one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve]
    choice_one = random.choice(list_one)
    choice_two = random.choice(list_one)
    choice_three = random.choice(list_one)
    choice_four = random.choice(list_one)
    choice_five = random.choice(list_one)
    choice_six = random.choice(list_one)
    choice_seven = random.choice(list_one)
    choice_eight = random.choice(list_one)
    choice_nine = random.choice(list_one)
    choice_ten = random.choice(list_one)
    choice_eleven = random.choice(list_one)
    choice_twelve = random.choice(list_one)
    choice_thirteen = random.choice(list_one)
    print(choice_one, choice_two, choice_three, choice_four, choice_five, choice_six, choice_seven, choice_eight, choice_nine, choice_ten, choice_eleven, choice_twelve, choice_thirteen)
if(a == 13):
    one = raw_input('Enter the first element.\n')
    two = raw_input('Enter the second element.\n')
    three = raw_input('Enter the third element.\n')
    four = raw_input('Enter the fourth element.\n')
    five = raw_input('Enter the fifth element.\n')
    six = raw_input('Enter the sixth element.\n')
    seven = raw_input('Enter the seventh element.\n')
    eight = raw_input('Enter the eighth element.\n')
    nine = raw_input('Enter the ninth element.\n')
    ten = raw_input('Enter the tenth element.\n')
    eleven = raw_input('Enter the eleventh element.\n')
    twelve = raw_input('Enter the twelth element.\n')
    thirteen = raw_input('Enter the thirteenth element.\n')
    list_one = [one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen]
    choice_one = random.choice(list_one)
    choice_two = random.choice(list_one)
    choice_three = random.choice(list_one)
    choice_four = random.choice(list_one)
    choice_five = random.choice(list_one)
    choice_six = random.choice(list_one)
    choice_seven = random.choice(list_one)
    choice_eight = random.choice(list_one)
    choice_nine = random.choice(list_one)
    choice_ten = random.choice(list_one)
    choice_eleven = random.choice(list_one)
    choice_twelve = random.choice(list_one)
    choice_thirteen = random.choice(list_one)
    choice_fourteen = random.choice(list_one)
    print(choice_one, choice_two, choice_three, choice_four, choice_five, choice_six, choice_seven, choice_eight, choice_nine, choice_ten, choice_eleven, choice_twelve, choice_thirteen, choice_fourteen)
if(a == 14):
    one = raw_input('Enter the first element.\n')
    two = raw_input('Enter the second element.\n')
    three = raw_input('Enter the third element.\n')
    four = raw_input('Enter the fourth element.\n')
    five = raw_input('Enter the fifth element.\n')
    six = raw_input('Enter the sixth element.\n')
    seven = raw_input('Enter the seventh element.\n')
    eight = raw_input('Enter the eighth element.\n')
    nine = raw_input('Enter the ninth element.\n')
    ten = raw_input('Enter the tenth element.\n')
    eleven = raw_input('Enter the eleventh element.\n')
    twelve = raw_input('Enter the twelth element.\n')
    thirteen = raw_input('Enter the thirteenth element.\n')
    fourteen = raw_input('Enter the fourteenth element.\n')
    list_one = [one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen]
    choice_one = random.choice(list_one)
    choice_two = random.choice(list_one)
    choice_three = random.choice(list_one)
    choice_four = random.choice(list_one)
    choice_five = random.choice(list_one)
    choice_six = random.choice(list_one)
    choice_seven = random.choice(list_one)
    choice_eight = random.choice(list_one)
    choice_nine = random.choice(list_one)
    choice_ten = random.choice(list_one)
    choice_eleven = random.choice(list_one)
    choice_twelve = random.choice(list_one)
    choice_thirteen = random.choice(list_one)
    choice_fourteen = random.choice(list_one)
    choice_fifteen = random.choice(list_one)
    print(choice_one, choice_two, choice_three, choice_four, choice_five, choice_six, choice_seven, choice_eight, choice_nine, choice_ten, choice_eleven, choice_twelve, choice_thirteen, choice_fourteen, choice_fifteen)
if(a == 15):
    one = raw_input('Enter the first element.\n')
    two = raw_input('Enter the second element.\n')
    three = raw_input('Enter the third element.\n')
    four = raw_input('Enter the fourth element.\n')
    five = raw_input('Enter the fifth element.\n')
    six = raw_input('Enter the sixth element.\n')
    seven = raw_input('Enter the seventh element.\n')
    eight = raw_input('Enter the eighth element.\n')
    nine = raw_input('Enter the ninth element.\n')
    ten = raw_input('Enter the tenth element.\n')
    eleven = raw_input('Enter the eleventh element.\n')
    twelve = raw_input('Enter the twelth element.\n')
    thirteen = raw_input('Enter the thirteenth element.\n')
    fourteen = raw_input('Enter the fourteenth element.\n')
    fifteen = raw_input('Enter the fifteenth element.\n')
    list_one = [one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen]
    choice_one = random.choice(list_one)
    choice_two = random.choice(list_one)
    choice_three = random.choice(list_one)
    choice_four = random.choice(list_one)
    choice_five = random.choice(list_one)
    choice_six = random.choice(list_one)
    choice_seven = random.choice(list_one)
    choice_eight = random.choice(list_one)
    choice_nine = random.choice(list_one)
    choice_ten = random.choice(list_one)
    choice_eleven = random.choice(list_one)
    choice_twelve = random.choice(list_one)
    choice_thirteen = random.choice(list_one)
    choice_fourteen = random.choice(list_one)
    choice_fifteen = random.choice(list_one)
    choice_sixteen = random.choice(list_one)
    print(choice_one, choice_two, choice_three, choice_four, choice_five, choice_six, choice_seven, choice_eight, choice_nine, choice_ten, choice_eleven, choice_twelve, choice_thirteen, choice_fourteen, choice_fifteen,choice_sixteen)
if(a == 16):
    one = raw_input('Enter the first element.\n')
    two = raw_input('Enter the second element.\n')
    three = raw_input('Enter the third element.\n')
    four = raw_input('Enter the fourth element.\n')
    five = raw_input('Enter the fifth element.\n')
    six = raw_input('Enter the sixth element.\n')
    seven = raw_input('Enter the seventh element.\n')
    eight = raw_input('Enter the eighth element.\n')
    nine = raw_input('Enter the ninth element.\n')
    ten = raw_input('Enter the tenth element.\n')
    eleven = raw_input('Enter the eleventh element.\n')
    twelve = raw_input('Enter the twelth element.\n')
    thirteen = raw_input('Enter the thirteenth element.\n')
    fourteen = raw_input('Enter the fourteenth element.\n')
    fifteen = raw_input('Enter the fifteenth element.\n')
    sixteen = raw_input('Enter the sixteenth element.\n')
    list_one = [one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen]
    choice_one = random.choice(list_one)
    choice_two = random.choice(list_one)
    choice_three = random.choice(list_one)
    choice_four = random.choice(list_one)
    choice_five = random.choice(list_one)
    choice_six = random.choice(list_one)
    choice_seven = random.choice(list_one)
    choice_eight = random.choice(list_one)
    choice_nine = random.choice(list_one)
    choice_ten = random.choice(list_one)
    choice_eleven = random.choice(list_one)
    choice_twelve = random.choice(list_one)
    choice_thirteen = random.choice(list_one)
    choice_fourteen = random.choice(list_one)
    choice_fifteen = random.choice(list_one)
    choice_sixteen = random.choice(list_one)
    choice_seventeen = random.choice(list_one)
    print(choice_one, choice_two, choice_three, choice_four, choice_five, choice_six, choice_seven, choice_eight, choice_nine, choice_ten, choice_eleven, choice_twelve, choice_thirteen, choice_fourteen, choice_fifteen,choice_sixteen, choice_seventeen)
if(a == 17):
    one = raw_input('Enter the first element.\n')
    two = raw_input('Enter the second element.\n')
    three = raw_input('Enter the third element.\n')
    four = raw_input('Enter the fourth element.\n')
    five = raw_input('Enter the fifth element.\n')
    six = raw_input('Enter the sixth element.\n')
    seven = raw_input('Enter the seventh element.\n')
    eight = raw_input('Enter the eighth element.\n')
    nine = raw_input('Enter the ninth element.\n')
    ten = raw_input('Enter the tenth element.\n')
    eleven = raw_input('Enter the eleventh element.\n')
    twelve = raw_input('Enter the twelth element.\n')
    thirteen = raw_input('Enter the thirteenth element.\n')
    fourteen = raw_input('Enter the fourteenth element.\n')
    fifteen = raw_input('Enter the fifteenth element.\n')
    sixteen = raw_input('Enter the sixteenth element.\n')
    seventeen = raw_input('Enter the seventeenth element.\n')
    list_one = [one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen]
    choice_one = random.choice(list_one)
    choice_two = random.choice(list_one)
    choice_three = random.choice(list_one)
    choice_four = random.choice(list_one)
    choice_five = random.choice(list_one)
    choice_six = random.choice(list_one)
    choice_seven = random.choice(list_one)
    choice_eight = random.choice(list_one)
    choice_nine = random.choice(list_one)
    choice_ten = random.choice(list_one)
    choice_eleven = random.choice(list_one)
    choice_twelve = random.choice(list_one)
    choice_thirteen = random.choice(list_one)
    choice_fourteen = random.choice(list_one)
    choice_fifteen = random.choice(list_one)
    choice_sixteen = random.choice(list_one)
    choice_seventeen = random.choice(list_one)
    choice_eighteen = random.choice(list_one)
    print(choice_one, choice_two, choice_three, choice_four, choice_five, choice_six, choice_seven, choice_eight, choice_nine, choice_ten, choice_eleven, choice_twelve, choice_thirteen, choice_fourteen, choice_fifteen,choice_sixteen, choice_seventeen, choice_eighteen)
if(a == 18):
    one = raw_input('Enter the first element.\n')
    two = raw_input('Enter the second element.\n')
    three = raw_input('Enter the third element.\n')
    four = raw_input('Enter the fourth element.\n')
    five = raw_input('Enter the fifth element.\n')
    six = raw_input('Enter the sixth element.\n')
    seven = raw_input('Enter the seventh element.\n')
    eight = raw_input('Enter the eighth element.\n')
    nine = raw_input('Enter the ninth element.\n')
    ten = raw_input('Enter the tenth element.\n')
    eleven = raw_input('Enter the eleventh element.\n')
    twelve = raw_input('Enter the twelth element.\n')
    thirteen = raw_input('Enter the thirteenth element.\n')
    fourteen = raw_input('Enter the fourteenth element.\n')
    fifteen = raw_input('Enter the fifteenth element.\n')
    sixteen = raw_input('Enter the sixteenth element.\n')
    seventeen = raw_input('Enter the seventeenth element.\n')
    eighteen = raw_input('Enter the eighteenth element.\n')
    list_one = [one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen]
    choice_one = random.choice(list_one)
    choice_two = random.choice(list_one)
    choice_three = random.choice(list_one)
    choice_four = random.choice(list_one)
    choice_five = random.choice(list_one)
    choice_six = random.choice(list_one)
    choice_seven = random.choice(list_one)
    choice_eight = random.choice(list_one)
    choice_nine = random.choice(list_one)
    choice_ten = random.choice(list_one)
    choice_eleven = random.choice(list_one)
    choice_twelve = random.choice(list_one)
    choice_thirteen = random.choice(list_one)
    choice_fourteen = random.choice(list_one)
    choice_fifteen = random.choice(list_one)
    choice_sixteen = random.choice(list_one)
    choice_seventeen = random.choice(list_one)
    choice_eighteen = random.choice(list_one)
    choice_nineteen = random.choice(list_one)
    print(choice_one, choice_two, choice_three, choice_four, choice_five, choice_six, choice_seven, choice_eight, choice_nine, choice_ten, choice_eleven, choice_twelve, choice_thirteen, choice_fourteen, choice_fifteen,choice_sixteen, choice_seventeen, choice_eighteen, choice_nineteen)
if(a == 19):
    one = raw_input('Enter the first element.\n')
    two = raw_input('Enter the second element.\n')
    three = raw_input('Enter the third element.\n')
    four = raw_input('Enter the fourth element.\n')
    five = raw_input('Enter the fifth element.\n')
    six = raw_input('Enter the sixth element.\n')
    seven = raw_input('Enter the seventh element.\n')
    eight = raw_input('Enter the eighth element.\n')
    nine = raw_input('Enter the ninth element.\n')
    ten = raw_input('Enter the tenth element.\n')
    eleven = raw_input('Enter the eleventh element.\n')
    twelve = raw_input('Enter the twelth element.\n')
    thirteen = raw_input('Enter the thirteenth element.\n')
    fourteen = raw_input('Enter the fourteenth element.\n')
    fifteen = raw_input('Enter the fifteenth element.\n')
    sixteen = raw_input('Enter the sixteenth element.\n')
    seventeen = raw_input('Enter the seventeenth element.\n')
    eighteen = raw_input('Enter the eighteenth element.\n')
    nineteen = raw_input('Enter the ninteenth element.\n')
    list_one = [one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen]
    choice_one = random.choice(list_one)
    choice_two = random.choice(list_one)
    choice_three = random.choice(list_one)
    choice_four = random.choice(list_one)
    choice_five = random.choice(list_one)
    choice_six = random.choice(list_one)
    choice_seven = random.choice(list_one)
    choice_eight = random.choice(list_one)
    choice_nine = random.choice(list_one)
    choice_ten = random.choice(list_one)
    choice_eleven = random.choice(list_one)
    choice_twelve = random.choice(list_one)
    choice_thirteen = random.choice(list_one)
    choice_fourteen = random.choice(list_one)
    choice_fifteen = random.choice(list_one)
    choice_sixteen = random.choice(list_one)
    choice_seventeen = random.choice(list_one)
    choice_eighteen = random.choice(list_one)
    choice_nineteen = random.choice(list_one)
    choice_twenty = random.choice(list_one)
    print(choice_one, choice_two, choice_three, choice_four, choice_five, choice_six, choice_seven, choice_eight, choice_nine, choice_ten, choice_eleven, choice_twelve, choice_thirteen, choice_fourteen, choice_fifteen,choice_sixteen, choice_seventeen, choice_eighteen, choice_nineteen, choice_twenty)
if(a == 20):
    one = raw_input('Enter the first element.\n')
    two = raw_input('Enter the second element.\n')
    three = raw_input('Enter the third element.\n')
    four = raw_input('Enter the fourth element.\n')
    five = raw_input('Enter the fifth element.\n')
    six = raw_input('Enter the sixth element.\n')
    seven = raw_input('Enter the seventh element.\n')
    eight = raw_input('Enter the eighth element.\n')
    nine = raw_input('Enter the ninth element.\n')
    ten = raw_input('Enter the tenth element.\n')
    eleven = raw_input('Enter the eleventh element.\n')
    twelve = raw_input('Enter the twelth element.\n')
    thirteen = raw_input('Enter the thirteenth element.\n')
    fourteen = raw_input('Enter the fourteenth element.\n')
    fifteen = raw_input('Enter the fifteenth element.\n')
    sixteen = raw_input('Enter the sixteenth element.\n')
    seventeen = raw_input('Enter the seventeenth element.\n')
    eighteen = raw_input('Enter the eighteenth element.\n')
    nineteen = raw_input('Enter the ninteenth element.\n')
    twenty = raw_input('Enter the twentieth element.\n')
    list_one = [one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen,twenty]
    choice_one = random.choice(list_one)
    choice_two = random.choice(list_one)
    choice_three = random.choice(list_one)
    choice_four = random.choice(list_one)
    choice_five = random.choice(list_one)
    choice_six = random.choice(list_one)
    choice_seven = random.choice(list_one)
    choice_eight = random.choice(list_one)
    choice_nine = random.choice(list_one)
    choice_ten = random.choice(list_one)
    choice_eleven = random.choice(list_one)
    choice_twelve = random.choice(list_one)
    choice_thirteen = random.choice(list_one)
    choice_fourteen = random.choice(list_one)
    choice_fifteen = random.choice(list_one)
    choice_sixteen = random.choice(list_one)
    choice_seventeen = random.choice(list_one)
    choice_eighteen = random.choice(list_one)
    choice_nineteen = random.choice(list_one)
    choice_twenty = random.choice(list_one)
    choice_twenty_one = random.choice(list_one)
    print(choice_one, choice_two, choice_three, choice_four, choice_five, choice_six, choice_seven, choice_eight, choice_nine, choice_ten, choice_eleven, choice_twelve, choice_thirteen, choice_fourteen, choice_fifteen,choice_sixteen, choice_seventeen, choice_eighteen, choice_nineteen, choice_twenty, choice_twenty_one)
raw_input('Press enter to exit.')




Assignment problems with simple random number generation in Modelica

I am relatively new to Modelica (Dymola-environment) and I am getting very desperate/upset that I cannot solve such a simple problem as a random number generation in Modelica and I hope that you can help me out. The simple function random produces a random number between 0 and 1 with an input seed seedIn[3] and produces the output seed seedOut[3] for the next time step or event. The call (z,seedOut) = random(seedIn); works perfectly fine.

The problem is that I cannot find a way in Modelica to compute this assignment over time by using the seedOut[3] as the next seedIn[3], which is very frustrating.

My simple program looks like this: *model Randomgenerator Real z; Integer seedIn3, seedOut[3]; equation (z,seedOut) = random(seedIn); algorithm seedIn := seedOut;

end Randomgenerator;*

I have tried nearly all possibilities with algorithm assignements, initial conditions and equations but none of them works. I just simply want to use seedOut in the next time step. One problem seems to be that when entering into the algorithm section, neither the initial conditions nor the values from the equation section are used.

I hope that you can help me with this problem.

Thanks, Daniel




Unable to call randomised Images correctly to parent array

Functionality Corresponding image will fade in and display when user clicks on the parent image. Therefore, the secondary image will correspond to the parent image.

What I have done:

All images are set into arrays, where they are all randomised. Furthermore, I have append the array of the corresponding images to the array of randomised image and append it to the displaying div tag.

I have attached the code for your perusal

//Brand Array
  var BrandNameArray = ["lib/img/PAGE03/Brands/anis.png", "lib/img/PAGE03/Brands/aeo.png", "lib/img/PAGE03/Brands/alo.png", "lib/img/PAGE03/Brands/beauty.png", "lib/img/PAGE03/Brands/bbe.png", "lib/img/PAGE03/Brands/eds.png", "lib/img/PAGE03/Brands/coch.png", "lib/img/PAGE03/Brands/cotnon.png", "lib/img/PAGE03/Brands/dewel.png", "lib/img/PAGE03/Brands/esdoir.png", "lib/img/PAGE03/Brands/erit.png", "lib/img/PAGE03/Brands/ethouse.png", "lib/img/PAGE03/Brands/forr2.png"];
  //Corresponding Image Array
  var OfferArray = ["lib/img/PAGE04/adonis.png", "lib/img/PAGE04/aeo.png", "lib/img/PAGE04/aldo.png", "lib/img/PAGE04/beauty.png", "lib/img/PAGE04/bebe.png", "lib/img/PAGE04/ceds.png", "lib/img/PAGE04/coach.png", "lib/img/PAGE04/cottonon.png", "lib/img/PAGE04/dejewel.png", "lib/img/PAGE04/esboudoir.png", "lib/img/PAGE04/esprit.png", "lib/img/PAGE04/etudehouse.png", "lib/img/PAGE04/forever21.png", ];
  var CorrectOfferArray = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
  var OfferIndex = "";

  $(function() {

    //Auto populate into brand container once randomised for each Brand image
    var BrandNameArrayBackup = JSON.parse(JSON.stringify(BrandNameArray));
    for (i = 0; i < $('#list').find('img').length; i++) {
      //To Set random Brand
      var random_BrandIndex = Math.floor(Math.random() * BrandNameArray.length);
      //Assign Variable to generate random Brands
      var Brand = BrandNameArray[random_BrandIndex];
      BrandNameArray.splice(random_BrandIndex, 1);
      $('#Brand_' + (i + 1)).attr('src', Brand);
      $('#Brand_' + (i + 1)).show();
      console.log(Brand);
    }
    BrandNameArray = BrandNameArrayBackup; //re-assigning values back to array
  });

  //Choose Brand with popUp
  function selectBrand(index) {

    $('#Vivo_BrandDescription').fadeIn({
      duration: slideDuration,
      queue: false
    });
    $("#All").hide();
    $("#Back").hide();
    $("#Beauty").hide();
    $("#Choose").hide();
    $("#Fashion").hide();

    var random_BrandIndex = Math.floor(Math.random() * BrandNameArray.length);
    var chosenBrandIndex = OfferArray[random_BrandIndex];
    //Set option clicked to CSS change 
    $('#Description').attr('src', chosenBrandIndex);
    $('#Description').show();
    OfferIndex = index + "";
  }

  function Vivo_BrandDescription() {
    idleTime = 0;

    $("#border_page").fadeOut(function() {
      $("#Vivo_BrandDescription").fadeIn();
    });
  }
<div id="ChooseBrand" align="center" style="position:absolute; width:1920px; height:1080px; background-repeat: no-repeat; z-index=3; top:0px; left:0px;">
  <img id="Main" src="lib/img/PAGE03/Background.png" />
  <input type="text" id="SearchField" style="position:absolute; top:190px; left:660px; height:40px; width:600px; outline=0px; border: 0; font-size:25px; font-family:'CenturyGothic'; background: transparent; z-index=4;" autofocus src="lib/img/transparent.png">
  <div class="Container">
    <div id="list" class="innerScroll">
      <!--1st Row-->
      <img id="Brand_1" style="width:284px; height:140px; top:0px; left:0px; border:0px; outline:0px" onclick="selectBrand('1');">
      <img id="Brand_2" style="width:284px; height:140px; top:0px; left:330px; border:0px;" onclick="selectBrand('2');">
      <img id="Brand_3" style="width:284px; height:140px; top:0px; left:650px; border:0px;" onclick="selectBrand('3');">
      <img id="Brand_4" style="width:284px; height:140px; top:0px; left:965px; border:0px;" onclick="selectBrand('4');">

      <!--2nd Row-->
      <img id="Brand_5" style="width:284px; height:140px; top:140px; left:0px; border:0px;" onclick="selectBrand('5');">
      <img id="Brand_6" style="width:284px; height:140px; top:140px; left:330px; border:0px;" onclick="selectBrand('6');">
      <img id="Brand_7" style="width:284px; height:140px; top:140px; left:650px; border:0px;" onclick="selectBrand('7');">
      <img id="Brand_8" style="width:284px; height:140px; top:140px; left:965px; border:0px;" onclick="selectBrand('8');">

      <!--3rd Row-->
      <img id="Brand_9" style="width:284px; height:140px; top:280px; left:0px; border:0px;" onclick="selectBrand('9');">
      <img id="Brand_10" style="width:284px; height:140px; top:280px; left:330px; border:0px;" onclick="selectBrand('10');">
      <img id="Brand_11" style="width:284px; height:140px; top:280px; left:650px; border:0px;" onclick="selectBrand('11');">
      <img id="Brand_12" style="width:284px; height:140px; top:280px; left:965px; border:0px;" onclick="selectBrand('12');">
    </div>

    <div id="BrandDescription" class="menu" align="center" style="position:absolute; width:1920px; height:1080px; background-repeat: no-repeat; display:none; top:0px; left:0px; z-index=10;">

      <img id="Description" style="position:absolute; top:124px; left:534px;z-index=11;">
      <button id="Close" onclick="Close()"></button>
      <button id="LikeBrand" onclick="LikeBrand()"></button>
      <button id="DislikeBrand" onclick="DislikeBrand()"></button>
      <button id="Reset" onclick="Reset()"></button>
    </div>

Issue:

The corresponding image when displayed does not tally with the parent image. Meaning: If the parent image is displaying an apple image, and when the user clicks on the apple image, the corresponding image that will be displayed is a worm. However, at this instance, when user clicks on the parent image of "apple", the corresponding image of a banana is shown. Therefore, the randomised corresponding image is showing the wrong image when the parent image is clicked.

What has caused an error in the function?? I am not getting it.