-1

I need help writing a code which randomly selects an adjustable amount of entries from a list and displays them for me. Preferably, I should be able to adjust the entries in the list aswell. So say I have a list with the numbers A through G, and I want the code to draw 7 different entries, it would show for instance "F C D A C G B". I would also like to be able to change the list from A through G to for instance words or other letters. I've tried several codes, but this is too advanced for me. I've read through several other forums and topics, but no one is able to help me. It's important to me that the design is simple, so all I want to have on my screen is a vertical list of entries, a small box to decide how many random draws to preform, and the result being displayed in a horizontal line. I'm not asking anyone to do the job for me, that would be rude, but I'm going about this the wrong way and I desperately need some guidance, because at this point I have no idea what I'm doing and everything I try turns out to be more complicated than what it needs to be.

Thanks in advance to anyone who can help me.

  • have you tried storing your entries into an array and then using php's array_rand() function? http://php.net/manual/en/function.array-rand.php – bio_sprite Jan 31 '17 at 03:22

1 Answers1

0

Shorter way to generate such a string using String.fromCharCode:

for (var i = 0, letter; i < 10; i++) {
    setTimeout(function() {
        letter = String.fromCharCode(97 + Math.floor(Math.random() * 26));
        out.appendChild(document.createTextNode(letter)); // append somewhere
    }, 2000 * i);
}

An example of how this code works can be seen here.

Colin
  • 865
  • 1
  • 6
  • 23
  • How would that be applied? it looks very compact. Thank you very much – user7492770 Jan 31 '17 at 03:25
  • I will edit my answer to include a demonstration that you can edit as you please. I am here to help, no question is stupid! – Colin Jan 31 '17 at 03:26
  • Thank you! that means alot to me. I used to code a lot before, but it was mostly setting up websites and I never really veered out of HTML, so I'm not good with programs and functions. – user7492770 Jan 31 '17 at 03:28
  • Completley understandable. I mostly work with JS and HTML. Feel free to upvote if you found this helpful. – Colin Jan 31 '17 at 03:30
  • Very helpful! but what does the "p=1, l=1, h=1, x=1, i=1, t=1, q=1, m=1, e=1, z=1" mean? and also, where is it picking it's items from? I would like to edit them. The entires for this particular purpose would be R2, L2, F2 and B2 – user7492770 Jan 31 '17 at 03:37
  • Also, I try upvoting, but my rep is under 15, so it makes no visual difference it says, though my feedback is recorded – user7492770 Jan 31 '17 at 03:42
  • Ah, understood. – Colin Jan 31 '17 at 03:44