I have 10 images and I want them to be prompt out randomly. What code should I use? I'm still an amateur so I hope I could get some answers here... The images are named like 'pic1', 'pic2' and so on. is it possible to get the number from the file name and use Math.random() ?
Store the pics in an Array.
Say array index is from 0 to 9
Use Java Math.random to get random number.
You need to multiply its result by 10 get indexes in your range
Related
I used the p5 editor to build an nft, and I'm working on getting it working in the fxhash sandbox. Using p5's random() function worked great when I uploaded my project to the sandbox, but quickly realized I needed to implement the fxrand() function to ensure that each individual iteration is the same when refreshing with the same hash.
Simply replacing all instances of the p5 random() function with fxrand() did not work, and I'm assuming because fxrand() simply generates a random number, whereas p5's random() function can be used in other ways (ie; random(-50, 50)).
How do I need to incorporate the fxrand() function into my project in a way that still works the same way as p5's random() function?
You may have already figured this out, and there's probably far better solutions (I'm very new to this), but here is what I figured out.
If I need a number from 0 to 9 then I can use this:
let randChoose1 = Math.floor(fxrand() * 10;
Anywhere I need to call that number I can simply use randChoose1 in place. For example, if I have an array named "bg" with 10 entries in the array, and I want to choose something from the array I can do this:
let randoBg = bg[randChoose1];
Maybe that's an image that I want to center on the canvas, I can call it with:
image(randoBg, width / 2, height / 2);
If I have 23 items in the array then I just need to declare randChoose1 with:
let randChoose1 = Math.floor(fxrand() * 23);
If you want to be able to have negative numbers be chosen, such as your example of a range from -50 to 50, it's just a matter of multiplying by rough total range you want and then subtracting half that.
let randChoose1 = Math.floor(fxrand() * 101 - 50;
In this case, randChoose1 will give you that range of results from -50 to 50. You have to multiply by 101 in order to make it possible for Math.floor to deliver 100 since it always rounds down.
If you found a better solution I'd love to hear it! This is something I'm struggling with as well, and my total experience with p5.js is less than a week at this point.
If you use randomSeed(int(fxrand()*987654321)) at the beginning of the setup function every time you call to the random function it will depend on fxrand
I have 8 images in a directory.
the path is /blabla.com/img.
I need to access this path and choose 3 out of 8 randomly and display those.
If 3 pics are the same, it should echo "yeeey".
Otherwise, "neeey" and record these responses in a text file.
I am not going to do your homework for you!
However I can give you some insight:
store your 8 file names in an array
call $RANDOM % 8 3 times and store the value in 3 index variables
use the 3 index variables to extract your 3 files
use sha256sum, sha512sum or md5sum to compute the signature of your images and store the result in 3 variables
compare the values of the 3 variables if they are the same echo "yeeey" else echo "neeey"
if on top of that you want to display the picture as written in your post you could call eog or other similar tool with the finename as parameter and of course in background, with a & at the end of the command call.
Good luck with your assignment and let me know if you need help!
let's array an array of distinct elements (for example 8):
array=({A..H})
(1) use RANDOM special variable modulo the number of elements to get a random number between 0 and number-1 inclusive
number=$((RANDOM%${#array[#]}))
the first random element is
first=${array[number]}
remove the element from array and reassign the array to reindex without gap (declare -p array to see)
unset array[number]
array=("${array[#]}")
restart from (1)
I am trying to create a data field using Mockaroo and they say they have Ruby support but I know nothing about Ruby so I am trying to find out how to do a field that will randomly choose between the 3 options.
now() or
now()+days(-1) or
now()+days(-2) or
now()+days(-3)
Idea 1
I was initially thinking something using random like now()+days(this.rand(-3))
Idea 2
I also thought of using or logic like now() or now()+days(-3) or etc...
This answer may end up being different than a typical ruby solution since Mockaroo has their own little API to use too... Appreciate any help that can be given.
Turns out I had to use the random function first and pass in min and max date parameters.
random(now()+days(2), now()+days(-3))
I'm want develop a system to print barcode using fastreport, but, I want print Code128B for numbers < 13 and EAN13 for numbers = 13.
How I can use two (2) types of barcode in my report? I using a databand.
Thanks!
I using Delphi and Fast Report 4.9
In your dataset make calculated fields for the numbers. If the number < 13 characters, set its value in the first field, if its 13 set it in the second.
Then place two barcode controls and make each display one of the fields. The other will be empty so it will not display anything.
This solution is probably easier and certainly faster than making FastReports handle this through scripting.
I just meet a problem. I use redis to store the geo information. for
example:
hset 10001 la 41.000333
hset 10001 lo 121.999999
or
zadd la 41.xxxxx pk-value
zadd lo 121.xxxxx pk-value
about 40000 key-values
the key is for the terminal id, and value is set, storing the termianl
gps info.
I have a requirement to computing the around terminal.
for example, my location is 41.000123, 121.999988, and I want to the
fastest compute the terminal around my location, I have idea how to
compute the two location's distance.
All I want is to think a way to fast iterate all data. In Redis 2.6 there is lua support. Can it help to resolve my problem?
You probably want to use geohashes, then you will be able to store (and search by) lon/lat with any precision you want, also it's relatively easy to get points which are in given bounding box.
For implementation with redis, have a look at geodis.
As I understand your question, you want to find all values close to some coordinates? One way would be to use Lua scripting, another would be to store one sorted set for each approximate latitude/longitude (if you know in advance which granularity you require). Example:
zadd la.41 41.000333 pk-value
zadd lo.121 121.999999 pk-value
Then, when you need to find something close to some coords (let's say (42.01, 122.03)), you would do something like:
lat = 42.01
lon = 122.03
lat_min, lat_mid, lat_max = round(lat - 1), round(lat), round(lat + 1)
lon_min, lon_mid, lon_max = round(lon - 1), round(lon), round(lon + 1)
Thus, you would look in the sorted sets la.41, la.42, la.43, lo.121, lo.122, lo.123:
zinterstore close.${lat},${lon} 6 la.${lat_min}, la.${lat_mid}, la.${lat_max}, lo.${lon_min}, lo.${lon_mid}, lo.${lon_max}
Now, close.${lat},${lon} should contain the id of every terminal close to the supplied coordinates.
Obviously, you could store each coordinate with greater granularity, like la.41.0, lo.121.0 and look only for terminals that close. Optionally, you could further filter the result in your client code.