Lacking...
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Lacking...

Started by pHaTTy, 25 December, 2003, 20:26:57

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

pHaTTy

Sorry i need to request this one :/

im lacking in knowledge, im spending to much time away from lua, i wrote a script just b4 went to run in ptokax realised id wrote it in a few differ languages :/

well anyways

i want to randomise a some lines in a file

eg

line1
line2
line3
line4

i very lacking here :/
Resistance is futile!

plop

easyest is 2 1st stuff the file into an associative array (table), by numbering the keys.
table = {["1"]=line1, etc....
for example you get 15 keys.
then you do tmp = random(15)
now you can call vallue's (lines) from the table by using table[tmp].

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

pHaTTy

QuoteOriginally posted by plop
easyest is 2 1st stuff the file into an associative array (table), by numbering the keys.
table = {["1"]=line1, etc....
for example you get 15 keys.
then you do tmp = random(15)
now you can call vallue's (lines) from the table by using table[tmp].

plop

hmm not exactly what im after tho :))))

just simple read stright from file and grab each line one by one, then randomize the outcome
Resistance is futile!

plop

you have this file

line1
line2
line3
line4

and want 2 make it like this?

line1
line4
line3
line2

or do you wanne pick a random like from the file?

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

pHaTTy

yep grab a random line, but directly from the file
Resistance is futile!

plop

never done it like that, i rather store stuff in memory as that is much faster.
but the next skips a random number of lines with a max of 15.
have the idea that this might skip the 1st line but it's up 2 you 2 solve that (easy do).
for i=1,random(15) do
   read("*l")
end
line = read()

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

pHaTTy

QuoteOriginally posted by plop
never done it like that, i rather store stuff in memory as that is much faster.
but the next skips a random number of lines with a max of 15.
have the idea that this might skip the 1st line but it's up 2 you 2 solve that (easy do).
for i=1,random(15) do
   read("*l")
end
line = read()

plop

thx plop i will give it a shot :))
Resistance is futile!

SMF spam blocked by CleanTalk