lundi 4 décembre 2023

Dummy data: generating random text and numerical data into one csv/excel file?

So I'm trying to generate dummy data that contains 3 columns: sq. feet, price and Borough. For the first two, which are purely numerical this is fine. I have 50,000 rows of data for both on a spreadsheet. However, when I add Borough and specify random values from a list I receive the following output:

       Sq. feet    Price  Borough
0           112   345382        5
1           310   901500        5
2           215   661033        5
3           147  1038431        5
4           212   296497        5

I have not used a package associated with numerical generation like np.random.randint

Instead I used "Borough" : random.randrange(len(word))

Where have I gone wrong?

My code below

import random

import pandas as pd
import numpy as np

WORDS = ["Chelsea", "Kensington", "Westminster", "Pimlico", "Bank", "Holborn", "Camden", "Islington", "Angel", "Battersea", "Knightsbridge", "Bermondsey", "Newham"]
word = random.choice(WORDS)
np.random.seed(1)
data3 = pd.DataFrame({"Sq. feet" : np.random.randint(low=75, high=325, size=50000),
                     "Price" : np.random.randint(low=200000, high=1250000, size=50000),
                      "Borough" : random.randrange(len(word))
                     })

df = pd.DataFrame(data3)
df.to_csv("/Users/thomasmcnally/PycharmProjects/real_estate_dummy_date/realestate.csv", index=False)

print(df)

I'm expecting a random line of word values from the WORDS [], instead the return value is just the number 5. It's obviously meaningless making another module just for the text-based data and printing them in different files.




dimanche 3 décembre 2023

What are the possibilities this code can produce an output which is dangerous for my computer? [closed]

enter image description here . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 😂😂😂😂😂Seriously asking...Any idea??? never tried it though...




samedi 2 décembre 2023

Program c that generate a random number to use it in guessing_number programme [duplicate]

I need a new function on C langue ( not the one that's existe in the library) tha generate a random number , then i will use it to tell the user if the number that he entered is lower.or.higher "I'm a beginner " Thank you

New function to generate number




Random walk algorithm

I'm trying to create a program which plots the different paths and points which you can take on the Cartesian plane using the following algorithm: Starting from the origin (0, 0), in step 1, you do one of the following:

*jump 1/2 to the right or 1/2 to left or terminate where you are.

If the movement hasn't ended yet, then in step 2:

*jump 1/4 upwards or 1/4 downwards or terminate where you are.

If the movement hasn't ended yet, then in step 3:

*jump 1/8 to the right or 1/8 to the left or terminate where you are,etc.

You would essentially do this indefinitely, where in step k, if k is even and the movement has not end yet, you would jump (1/2)^k upwards or downwards. Similarly, in step k if k is odd you jump (1/2)^k to the right or left or terminate where you are.

I want to plot the set of endpoints you can reach in this way in finitely many steps. Is the following code correct? By the way,the coloured circles at the end of each path is an endpoint. Are these plotted correctly?

import numpy
import pylab
import random
import matplotlib.pyplot as plt
axes = plt.axes()
k = 50

x = numpy.zeros(k)
y = numpy.zeros(k)
lst = []
for j in range(1,30):
  for i in range(1,k):
    dir = [-1,1][random.randint(0,1)]
    if i%2!=0:
        x[i] = x[i - 1] + 1/(2**(i)) * dir
        y[i] = y[i - 1]
    else:
      x[i] = x[i - 1]
      y[i] = y[i - 1] + 1/(2**(i)) * dir
  plt.plot(x, y,marker = 'o')
plt.title("Different paths the random walk movement sequences could take")
pylab.show()

Graph of possible paths plotted




vendredi 1 décembre 2023

How can I ask a user with the scanner to insert the ammount of random numbers he/she would like to be created and sort it f. e. with bubblesort?

I am currently studying computer science in my first semester and I have an assignment I need some kind help with. I am supposed to create an array which fills in the amount of random numbers the user specifies using the java.util.Scanner. Currently my code looks like this:

package lia.prog1.exercises.set09;

import java.util.Scanner;
import java.util.Random;

public class SortingTool
{

    private void bubblesort(int[] arr)
    {
        int sortArray;
        int i;
        int j;
        int tempArray;

        Scanner scanner = new Scanner(System.in);
        sortArray = scanner.nextInt();
        System.out.println("How many numbers do you want to sort?");



        for (i = 0; i < (arr.length - 1); i++)
        {
            for (j = 0; j < arr.length - i - 1; j++)
            {
                if (arr[j] > arr[j + 1])
                {
                    tempArray = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = tempArray;
                }
            }
        }
    }

    private void insertionsort(int [] data)
    {
        int [] sorted = new int[data.length];

        for (int i = 0; i < data.length; i++)
        {
            int min = Integer.MAX_VALUE;
            for (int j = 0; j < data.length; j++)
            {
                if (min > data[j])
                {
                    int temp = min;
                    min = data[j];
                    data[j] = temp;
                }
            }
            sorted[i] = min;
        }
    }

}



Difficulty with Rock Paper Scissors game

I'm making a code in Java that is a rock-paper-scissors game. In particular, I am trying to make it so that the randomized outputs, aka if a user loses, wins, or ties, it is counted into the score.

For example, the user inputs either rock, paper, or scissors. If they choose rock, they will get a random output that determines whether or not they win, lose, or tie. If they got the output, let's say, "You chose rock. I chose paper. You lose!" I want to add that score result as "1 loss." in my while loop. However, I don't know how to make the program count the random outputs like that.

My code is below and I put comments in it to try and better explain what I want to do.

import java.util.Random; 
import java.util.Scanner;

public class rockpaperscissors {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

while(true){

    System.out.println("Please choose (r)ock, (p)aper or (s)cissors:");
    String answer = input.nextLine();
    int win = 0;
    int lose = 0;
    int tie = 0;
    
    if(answer.equals("r")) {
        String[] str = { "You chose rock. I chose paper. You lose!", /* lose++; */ "You chose rock. I chose scissors. You win!",  /* win++; */ "You chose rock. I chose rock. We tie!"  /* tie++; */ };
        Random r = new Random();
        System.out.println(str[r.nextInt(3)]);
        
        
     
    }
    if(answer.equals("p")) {
        String[] str = { "You chose paper. I chose scissors. You lose!",  /* lose++; */ "You chose paper. I chose rock. You win!",  /* win++; */ "You chose paper. I chose paper. We tie!"  /* tie++; */ };
        Random r = new Random();
        System.out.println(str[r.nextInt(3)]);
   
  }
    if(answer.equals("s")) {
        String[] str = { "You chose scissors. I chose rock. You lose!",  /* lose++; */ "You chose scissors. I chose paper. You win!",  /* win++; */ "You chose scissors. I chose scissors. We tie!"  /* tie++; */ };
        Random r = new Random();
        System.out.println(str[r.nextInt(3)]);
   
  }
  
    
    System.out.println("Score: " + win + " win(s), " + lose + " loss(es), " + tie + " tie(s)");
  System.out.println("Play again (y/n)?"); 
   String c = input.nextLine();

   if(c.equalsIgnoreCase("n")){ 
      break;
     }

}

}
}

I've tried using switch statements, but they haven't been working out. I've also been trying to use if statements but my code never works. Please note that I'm still fairly new to java so there are functions that I am quite unfamiliar with.




jeudi 30 novembre 2023

Change URL every 10min based on redirect

I got 10 urls in a file.

I want to show each url for 10 minutes and when done start over again.

<?php

$version = "v1.01";

$linksfile = "urlrotator.txt";

$urls = file("$linksfile");
$url = rand(0, sizeof($urls) - 1);

$goto = "$urls[$url]";

header("Location: $goto");

This just rotate random.

Need to be based on time

The urlrotator.txt content look like following

nr1.html
nr2.html
nr3.html
nr4.html
nr5.html
nr6.html
nr7.html
nr8.html
nr9.html
nr10.html