vendredi 24 janvier 2020

How to randomly place signal portions to a time series in python?

I have 100 signal portions, which I want to sum them randomly to a time series which is a white noise. i want to finally create a 24 hours time series which these 100 portions is randomly distributed over it. I create white noise for 24 hours as below:

dt=1/100
nt = 86400 / dt   
t=np.arange(dt,nt*dt,dt)
noise= np.random.randn(len(t))

each signal portion is 12 seconds. I do not know how to distribute these 100 portions randomly in created white noise. Also I need to know the exact second which each 100 portion is added to the noise.




Random elements inside JOIN

I have this code here

INSERT INTO Directory.CatalogTaxonomy (`CatalogId`, `TaxonomyId`, `TaxonomyTypeId`, `IsApprovalRelevant`)
SELECT cat.CatalogId, dep.Id, @department_type, false
FROM Directory.Catalog cat
    JOIN (SELECT * FROM (
        SELECT * FROM Taxonomy.Department LIMIT 10
    ) as dep_tmp ORDER BY RAND() LIMIT 3) AS dep
WHERE cat.CatalogId NOT IN (SELECT CatalogId FROM Directory.CatalogTaxonomy WHERE TaxonomyTypeId = @department_type) 
    AND cat.UrlStatus = @url_status_green 
    AND (cat.StatusId = @status_published 
        OR cat.StatusId = @status_review_required);

And the problem is that, it should for each catalog take the first 10 elements from Department and randomly choose 3 of them, then add to CatalogDepartment 3 rows, each containing the catalog id and a taxonomy id. But instead it randomly chooses 3 Department elements and then adds those 3 elements to each catalog.

The current result looks like this:

1   000de9d7-af8b-4bac-bdbd-e6e361e5bc5e
1   001d4060-2924-4c75-b304-d780454f261b
1   001bc4b8-c1bc-498d-9aee-3825a40587d5
2   000de9d7-af8b-4bac-bdbd-e6e361e5bc5e
2   001d4060-2924-4c75-b304-d780454f261b
2   001bc4b8-c1bc-498d-9aee-3825a40587d5
3   000de9d7-af8b-4bac-bdbd-e6e361e5bc5e
3   001d4060-2924-4c75-b304-d780454f261b
3   001bc4b8-c1bc-498d-9aee-3825a40587d5

As you can see, there are only 3 departments chosen and repeated for every catalog




Generate random integers between1000 and 9999

import random

liste=[i for i in range(1000,9999)]

if len(set(str(i))) == len(str(i))
   a=random.choise(liste)
   print(a)

random numbers but unrepeated! for example: '1242' no way! because; '2' twice written




jeudi 23 janvier 2020

How to disable a script which is attached to random characters in Unity?

I've been developing a game but there is something that I can't figure out because of being a little bit new in the language and the editor. I create some random characters that have a basic movement script. Yet I also use collision for making them stop when they touch something. So the problem occurs at this point. I should get all the characters in an array and then I should use a loop as far as I know but I cannot do that because I have a generator and I don't know the numbers of the characters and I can't add them as a component to main script.

So how can I solve this?




random number generator with interactive variable

Could someone help me with this its little messy code , but i want to switch theese two if Min > Max because when is min > than max the code still works and its giving wrong numbers , or any advices how to make it cleaner . Thanks a lot

const inputMin = document.getElementById('min');  
const inputMax = document.getElementById('max');
const done = document.getElementById('value');
const rGen = document.getElementById('rGen');

let min = 1;
let max = 100;

inputMin.addEventListener('input', updateValue);
function updateValue(ef) {
    min = + ef.target.value ;      
}
inputMax.addEventListener('input', updateValue1);

function updateValue1(e) {
    max = + e.target.value;

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

}

rGen.addEventListener('submit', (e) => {

    done["innerText"] = randomNumber(min, max);

    e.preventDefault()


});

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>generator</title>
<link rel="stylesheet" type="text/css" href="css/style.css">

</head>
    <body>

 <form id="rGen" class="form">
    <h1>Click generate </bold></h1>
    <label
            for="min">od
    </label>
    <input type="number" id="min" placeholder='1'>
    <label for="max">do</label>
    <input type="number" id="max" placeholder="100"  size="10"> <br>
    <button class="butt">GENERATE</button>
    <div id="value">
        7
    </div>
 </form>



 <script src="js/script.js"></script>

``




Shuffle giving same order [duplicate]

When I shuffle several sublists they come out in the same order. I'm sure I can reseed it with a random number each time, but everything I read implies that I shouldn't have to.
Code:

test=[list(range(10))]*5
import random
for x in test:
    random.shuffle(x)

print(test)

Results:

[[0, 8, 9, 6, 1, 2, 7, 4, 5, 3], [0, 8, 9, 6, 1, 2, 7, 4, 5, 3], [0, 8, 9, 6, 1, 2, 7, 4, 5, 3], [0, 8, 9, 6, 1, 2, 7, 4, 5, 3], [0, 8, 9, 6, 1, 2, 7, 4, 5, 3]]

Why isn't shuffle producing different orders?




How can I create a function to call a random variable and then call a random from the array of the first random? [closed]

var movieFlavor = ['War', 'Love', 'True', ]

var warMovies = ['Pearl Harbor', 'PT 109', 'FireBase Gloria', ]

//Button to get Movie Flavor

function randMovieFlavor() {
  var randomNumber = Math.floor(Math.random() * (movieFlavor.length));
  document.getElementById('movieDisplay3').innerHTML = movieFlavor[randomNumber];
}

//Button (trying) to get a random movie from the flavor array answer.
function craigsPick() {
  var randomNumber = Math.floor(Math.random() * (randMovieFlavor.length) * movieFlavor);
  document.getElementById('movieDisplay').innerHTML = randMovieFlavor * movieFlavor[randomNumber];
}

What kind of more details without writing a book?