samedi 2 janvier 2016

TypingError : randint() takes exactly 3 arguments (2 given)

I know there is a similar question/problem to this on stakeflow but the answer didn't help me. My code :

import random
name=input("Welcome to this Arithmetic quiz,please enter your name:")
number1=random.randint(1,50)

number2=random.randint(1,50)


oper=random.randint('+','-','*')

input('question 1 is:'+str(number1)+'oper'+str(number2)+'=')

For line 5 it gives me this error^^.I am trying to create 2 random numbers with 1 random operation and input it together for the user.

P.S. When I input the question how will python know if the answer is right or wrong? Or do I have to say 'if answer=True' print('correct') else: print('Incorrect').




Create a random number and check if it is odd or even

I am looking to create a batch file that, when ran, creates a random integer from 0 to 100 and then runs it through an if statement that checks whether it is odd or even. I've been having some trouble, so here is what I have so far.

@echo off
set /a num=%random% %%100 +1
if ( num % 2 == 0 ) {

//even

}

else

{

    //odd


}




vendredi 1 janvier 2016

std::vector randomly adds elements to vector

I am sorting points, the code that I wrote for the sorting part works perfectly, but I have one issue. Every so often (at random times) random points are added to the end of the vector, and when I try to pop_back() to delete these last elements (because I wrote a small portion to check to make sure the number of points are the same), I end up in an infinite loop trying to delete these last elements, which just won't go away. Is there something I should know? Also some of the points randomly disappear even when I do not try to delete them. I am trying to understand what I need to exactly do to prevent these weird points from poping up, because these points are sorted in a specific order.

I only have three insert methods, and the first is an emplace_back(), the next is an insert, and the last is also an insert method:

                if (afterX >= spheres.capacity())
                    spheres.emplace_back(center);
                else if(afterX == -1)
                    spheres.insert(spheres.begin(),center);
                else
                    spheres.insert(std::next( spheres.begin(), afterX ),center);
                elementCount++;

Here is my output, to get an idea:

Point: <5,0,0>
zFind: -1
<5,0,0>
Point: <10,0,0>
zFind: 0
yFind: 0
<5,0,0><10,0,0>
Point: <100,0,0>
zFind: 0
yFind: 0
<5,0,0><10,0,0><100,0,0><2.11207e-023,0,0>
Point: <30,0,0>
zFind: 0
yFind: 0
<5,0,0><10,0,0><30,0,0><100,0,0>
Point: <20,0,0>
zFind: 0
yFind: 0
<5,0,0><10,0,0><20,0,0><30,0,0><100,0,0><2.10934e-023,2.21351e+033,0><0,0,2.21351e+033><0,0,0>

As you can see the point: Point is added correctly in the series (least to greatest), but these are odd extra numbers at the end that are there and then disappear.

Thanks, Simon




Variable Interval NSTimer

I am trying to create a NSTimer that executes an action at a random interval. So it will fire, wait a random time, fire, wait a different random time, etc. Is there a simple way to do this?




Make an array of random unique numbers in a certain range

I'm working on a school project and I need to create an array (size of 30) of random unique numbers between 1 and 70.

I managed to find how to create an array of random unique numbers, but not between 1 and 70.

public int[] ShuffleArray(int[] arr)
{
    Random rand = new Random();
    int[] array = new int[70];
    for (int i = 0; i < 70; i++)
        array[i] = i + 1;
    int[] MyRandomArray = array.OrderBy(x => rand.Next(1, 71)).ToArray();
    for (int k = 0; k < arr.Length; k++)
        arr[k] = MyRandomArray[k];
    return arr;
}

I changed it based on feedback, but it still doesn't work.




Generate the same semi random number on two machines

I was wondering if there is a way to generate the same semi random number on two machines at the same time. Here is an example of how I am currently getting my randoms.

var randomValue = generateRandom( -200, 200 );

function generateRandom( min, max ) 
{
    min = Math.ceil( min );
    max = Math.floor( max );
    return Math.floor( Math.random() * ( max - min + 1 ) + min );
}

What I can do is send message between the two devices. I don't know if that will help because randomValue is being called within a function. I was thinking maybe we can use a timer or something to generate the value on both machines.




javascript random number variable to php

Hello i use javascript to roll a dice and pick random number. After this the script have to show this number in the div box and make a variable with the number. The problem is that it's starting from 1 and picking numbers +4...(example: 1st pick - 1, 2nd pick 5, 3th pick 9, 4th pick 13 etc) it's not picking random number...

This is the code for random pick:

var loop = setInterval(function(){
                    $('.rolling_bet').html(getRandomInt(0, 9999));
                }, 100);

and this is the code for transfering the variable to php:

$.post( "http://localhost/play.php", {'amount': amount, 'type': type, 'loop': loop}, function( data ){    (etc..)

am i right to use "loop" variable to post it or my javascript code is wrong?