diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 6cb0dc0740..b1bd0a4bc9 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -65,6 +65,10 @@ and integration scripts to allow running the current Logtalk version. Library ------- +* ADDED: Predicate `randomize/1` to the `random` library. + +* ADDED: Faster version of the `random` library object, `frandom`. + * ADDED: Implementation of the `os::time_stamp/1` predicate for CxProlog. * FIXED: Declaration of the return type for the `os::time_stamp/1` predicate. diff --git a/docs/core_inheritance_diagram.svg b/docs/core_inheritance_diagram.svg index 2f7a265f07..58665bfda3 100644 --- a/docs/core_inheritance_diagram.svg +++ b/docs/core_inheritance_diagram.svg @@ -1,7 +1,7 @@ - core Logtalk core entities -Generated on 2017/01/13, 19:27 +Generated on 2017/02/25, 11:46 cluster_library_core diff --git a/docs/directory_index.html b/docs/directory_index.html index 4c8d53959e..e91f1e0bfd 100644 --- a/docs/directory_index.html +++ b/docs/directory_index.html @@ -169,6 +169,11 @@

float +
+ + frandom + +
gensym diff --git a/docs/entity_index.html b/docs/entity_index.html index bbc2a6a50d..7d25b44a81 100644 --- a/docs/entity_index.html +++ b/docs/entity_index.html @@ -273,6 +273,11 @@

float

+
+ + frandom + +
gensym diff --git a/docs/index.html b/docs/index.html index 17ec77b20a..9773160f31 100644 --- a/docs/index.html +++ b/docs/index.html @@ -16,6 +16,6 @@

Documentation index

  • Entity index
  • Predicate index
  • -

    Generated on Tue Feb 21 00:30:48 GMT 2017

    +

    Generated on Sat Feb 25 11:46:28 GMT 2017

    diff --git a/docs/library_index.html b/docs/library_index.html index e41a69ff48..b3d2c98dac 100644 --- a/docs/library_index.html +++ b/docs/library_index.html @@ -449,6 +449,11 @@

    float

    +
    + + frandom + +
    gensym diff --git a/docs/library_inheritance_diagram.svg b/docs/library_inheritance_diagram.svg index b06a060c10..a9541d42ed 100644 --- a/docs/library_inheritance_diagram.svg +++ b/docs/library_inheritance_diagram.svg @@ -1,20 +1,20 @@ - - + library - + Logtalk library -Generated on 2017/01/31, 14:12 +Generated on 2017/02/25, 11:46 cluster_library_library - + library @@ -22,632 +22,640 @@ cluster_file_/Users/pmoura/logtalk/library/osp.lgt - -osp.lgt + +osp.lgt cluster_file_/Users/pmoura/logtalk/library/os.lgt - -os.lgt + +os.lgt cluster_file_/Users/pmoura/logtalk/library/termp.lgt - -termp.lgt + +termp.lgt cluster_file_/Users/pmoura/logtalk/library/term.lgt - -term.lgt + +term.lgt cluster_file_/Users/pmoura/logtalk/library/atomic.lgt - -atomic.lgt + +atomic.lgt cluster_file_/Users/pmoura/logtalk/library/atom.lgt - -atom.lgt + +atom.lgt cluster_file_/Users/pmoura/logtalk/library/number.lgt - -number.lgt + +number.lgt cluster_file_/Users/pmoura/logtalk/library/float.lgt - -float.lgt + +float.lgt cluster_file_/Users/pmoura/logtalk/library/integer.lgt - -integer.lgt + +integer.lgt cluster_file_/Users/pmoura/logtalk/library/compound.lgt - -compound.lgt + +compound.lgt cluster_file_/Users/pmoura/logtalk/library/listp.lgt - -listp.lgt + +listp.lgt cluster_file_/Users/pmoura/logtalk/library/list.lgt - -list.lgt + +list.lgt cluster_file_/Users/pmoura/logtalk/library/type.lgt - -type.lgt + +type.lgt cluster_file_/Users/pmoura/logtalk/library/pairs.lgt - -pairs.lgt + +pairs.lgt cluster_file_/Users/pmoura/logtalk/library/callable.lgt - -callable.lgt + +callable.lgt cluster_file_/Users/pmoura/logtalk/library/characterp.lgt - -characterp.lgt + +characterp.lgt cluster_file_/Users/pmoura/logtalk/library/character.lgt - -character.lgt + +character.lgt cluster_file_/Users/pmoura/logtalk/library/natural.lgt - -natural.lgt + +natural.lgt cluster_file_/Users/pmoura/logtalk/library/list1.lgt - -list1.lgt + +list1.lgt cluster_file_/Users/pmoura/logtalk/library/difflist.lgt - -difflist.lgt + +difflist.lgt cluster_file_/Users/pmoura/logtalk/library/numberlistp.lgt - -numberlistp.lgt + +numberlistp.lgt cluster_file_/Users/pmoura/logtalk/library/numberlist.lgt - -numberlist.lgt + +numberlist.lgt cluster_file_/Users/pmoura/logtalk/library/varlistp.lgt - -varlistp.lgt + +varlistp.lgt cluster_file_/Users/pmoura/logtalk/library/varlist.lgt - -varlist.lgt + +varlist.lgt cluster_file_/Users/pmoura/logtalk/library/queuep.lgt - -queuep.lgt + +queuep.lgt cluster_file_/Users/pmoura/logtalk/library/queue.lgt - -queue.lgt + +queue.lgt cluster_file_/Users/pmoura/logtalk/library/dictionaryp.lgt - -dictionaryp.lgt + +dictionaryp.lgt cluster_file_/Users/pmoura/logtalk/library/bintree.lgt - -bintree.lgt + +bintree.lgt cluster_file_/Users/pmoura/logtalk/library/rbtree.lgt - -rbtree.lgt + +rbtree.lgt cluster_file_/Users/pmoura/logtalk/library/setp.lgt - -setp.lgt + +setp.lgt cluster_file_/Users/pmoura/logtalk/library/set.lgt - -set.lgt + +set.lgt cluster_file_/Users/pmoura/logtalk/library/set1.lgt - -set1.lgt + +set1.lgt cluster_file_/Users/pmoura/logtalk/library/heapp.lgt - -heapp.lgt + +heapp.lgt cluster_file_/Users/pmoura/logtalk/library/heaps.lgt - -heaps.lgt + +heaps.lgt cluster_file_/Users/pmoura/logtalk/library/comparingp.lgt - -comparingp.lgt + +comparingp.lgt cluster_file_/Users/pmoura/logtalk/library/randomp.lgt - -randomp.lgt + +randomp.lgt cluster_file_/Users/pmoura/logtalk/library/random.lgt - -random.lgt + +random.lgt +cluster_file_/Users/pmoura/logtalk/library/frandom.lgt + + +frandom.lgt + + + + cluster_file_/Users/pmoura/logtalk/library/arbitrary.lgt - - -arbitrary.lgt + + +arbitrary.lgt - + cluster_file_/Users/pmoura/logtalk/library/datep.lgt - - -datep.lgt + + +datep.lgt - + cluster_file_/Users/pmoura/logtalk/library/date.lgt - + date.lgt - + cluster_file_/Users/pmoura/logtalk/library/timep.lgt - - -timep.lgt + + +timep.lgt - + cluster_file_/Users/pmoura/logtalk/library/time.lgt - + time.lgt - + cluster_file_/Users/pmoura/logtalk/library/event_registryp.lgt - - -event_registryp.lgt + + +event_registryp.lgt - + cluster_file_/Users/pmoura/logtalk/library/event_registry.lgt - - -event_registry.lgt + + +event_registry.lgt - + cluster_file_/Users/pmoura/logtalk/library/before_event_registry.lgt - - -before_event_registry.lgt + + +before_event_registry.lgt - + cluster_file_/Users/pmoura/logtalk/library/after_event_registry.lgt - - -after_event_registry.lgt + + +after_event_registry.lgt - + cluster_file_/Users/pmoura/logtalk/library/monitorp.lgt - + monitorp.lgt - + cluster_file_/Users/pmoura/logtalk/library/monitor.lgt - + monitor.lgt - + cluster_file_/Users/pmoura/logtalk/library/observer.lgt - + observer.lgt - + cluster_file_/Users/pmoura/logtalk/library/subject.lgt - + subject.lgt - + cluster_file_/Users/pmoura/logtalk/library/hierarchyp.lgt - - -hierarchyp.lgt + + +hierarchyp.lgt - + cluster_file_/Users/pmoura/logtalk/library/proto_hierarchyp.lgt - - -proto_hierarchyp.lgt + + +proto_hierarchyp.lgt - + cluster_file_/Users/pmoura/logtalk/library/proto_hierarchy.lgt - + proto_hierarchy.lgt - + cluster_file_/Users/pmoura/logtalk/library/class_hierarchyp.lgt - - -class_hierarchyp.lgt + + +class_hierarchyp.lgt - + cluster_file_/Users/pmoura/logtalk/library/class_hierarchy.lgt - + class_hierarchy.lgt - + cluster_file_/Users/pmoura/logtalk/library/metap.lgt - - -metap.lgt + + +metap.lgt - + cluster_file_/Users/pmoura/logtalk/library/meta.lgt - + meta.lgt - + cluster_file_/Users/pmoura/logtalk/library/loopp.lgt - - -loopp.lgt + + +loopp.lgt - + cluster_file_/Users/pmoura/logtalk/library/loop.lgt - + loop.lgt - + cluster_file_/Users/pmoura/logtalk/library/statisticsp.lgt - - -statisticsp.lgt + + +statisticsp.lgt - + cluster_file_/Users/pmoura/logtalk/library/statistics.lgt - - -statistics.lgt + + +statistics.lgt - + cluster_file_/Users/pmoura/logtalk/library/population.lgt - + population.lgt - + cluster_file_/Users/pmoura/logtalk/library/sample.lgt - + sample.lgt - + cluster_file_/Users/pmoura/logtalk/library/intervalp.lgt - + intervalp.lgt - + cluster_file_/Users/pmoura/logtalk/library/interval.lgt - + interval.lgt - + cluster_file_/Users/pmoura/logtalk/library/loggingp.lgt - + loggingp.lgt - + cluster_file_/Users/pmoura/logtalk/library/logging.lgt - + logging.lgt - + cluster_file_/Users/pmoura/logtalk/library/logger.lgt - + logger.lgt - + cluster_file_/Users/pmoura/logtalk/library/gensym.lgt - + gensym.lgt - + cluster_file_/Users/pmoura/logtalk/library/meta_compiler.lgt - + meta_compiler.lgt - + cluster_file_/Users/pmoura/logtalk/library/assignvarsp.lgt - + assignvarsp.lgt - + cluster_file_/Users/pmoura/logtalk/library/nd_assignvars.lgt - + nd_assignvars.lgt - + cluster_file_/Users/pmoura/logtalk/library/hook_pipeline.lgt - + hook_pipeline.lgt - + cluster_file_/Users/pmoura/logtalk/library/hook_set.lgt - + hook_set.lgt - + cluster_file_/Users/pmoura/logtalk/library/java_protocols.lgt - + java_protocols.lgt - + cluster_file_/Users/pmoura/logtalk/library/java_jpl.lgt - + java_jpl.lgt - + cluster_file_/Users/pmoura/logtalk/library/counters.lgt - + counters.lgt - + cluster_file_/Users/pmoura/logtalk/library/streamvars.lgt - + streamvars.lgt - + cluster_other - - -(external entities) + + +(external entities) @@ -655,91 +663,91 @@ osp - - - - -osp - - -protocol - - - -pid/1 - - -shell/2 - - -shell/1 - - -expand_path/2 - - -decompose_file_name/4 - - -make_directory/1 - - -make_directory_path/1 - - -delete_directory/1 - - -change_directory/1 - - -working_directory/1 - - -directory_files/2 - - -directory_exists/1 - - -file_exists/1 - - -file_modification_time/2 - - -file_size/2 - - -file_permission/2 - - -rename_file/2 - - -delete_file/1 - - -environment_variable/2 - - -time_stamp/1 - - -date_time/7 - - -cpu_time/1 - - -wall_time/1 - - -operating_system_type/1 - - -command_line_arguments/1 - + + + + +osp + + +protocol + + + +pid/1 + + +shell/2 + + +shell/1 + + +expand_path/2 + + +decompose_file_name/4 + + +make_directory/1 + + +make_directory_path/1 + + +delete_directory/1 + + +change_directory/1 + + +working_directory/1 + + +directory_files/2 + + +directory_exists/1 + + +file_exists/1 + + +file_modification_time/2 + + +file_size/2 + + +file_permission/2 + + +rename_file/2 + + +delete_file/1 + + +environment_variable/2 + + +time_stamp/1 + + +date_time/7 + + +cpu_time/1 + + +wall_time/1 + + +operating_system_type/1 + + +command_line_arguments/1 + @@ -747,13 +755,13 @@ os - - -os - - -prototype - + + +os + + +prototype + @@ -761,59 +769,59 @@ os->osp - - + + -implements +implements termp - - - - -termp - - -protocol - - - -depth/2 - - -ground/1 - - -new/1 - - -occurs/2 - - -subsumes/2 - - -subterm/2 - - -valid/1 - - -check/1 - - -variant/2 - - -variables/2 - - -singletons/2 - + + + + +termp + + +protocol + + + +depth/2 + + +ground/1 + + +new/1 + + +occurs/2 + + +subsumes/2 + + +subterm/2 + + +valid/1 + + +check/1 + + +variant/2 + + +variables/2 + + +singletons/2 + @@ -821,13 +829,13 @@ term - - -term - - -prototype - + + +term + + +prototype + @@ -835,23 +843,23 @@ term->termp - - + + -implements +implements atomic - - -atomic - - -prototype - + + +atomic + + +prototype + @@ -859,30 +867,30 @@ atomic->term - - + + -extends +extends atom - - -atom - - -prototype - - - -replace_sub_atom/4 - - -split/3 - + + +atom + + +prototype + + + +replace_sub_atom/4 + + +split/3 + @@ -890,23 +898,23 @@ atom->atomic - - + + -extends +extends number - - -number - - -prototype - + + +number + + +prototype + @@ -914,23 +922,23 @@ number->atomic - - + + -extends +extends float - - -float - - -prototype - + + +float + + +prototype + @@ -938,36 +946,36 @@ float->number - - + + -extends +extends integer - - -integer - - -prototype - - - -between/3 - - -plus/3 - - -succ/2 - - -sequence/3 - + + +integer + + +prototype + + + +between/3 + + +plus/3 + + +succ/2 + + +sequence/3 + @@ -975,23 +983,23 @@ integer->number - - + + -extends +extends compound - - -compound - - -prototype - + + +compound + + +prototype + @@ -999,158 +1007,158 @@ compound->term - - + + -extends +extends listp - - - - -listp - - -protocol - - - -append/2 - - -append/3 - - -delete/3 - - -delete_matches/3 - - -empty/1 - - -flatten/2 - - -hamming_distance/3 - - -keysort/2 - - -last/2 - - -length/2 - - -max/2 - - -member/2 - - -memberchk/2 - - -min/2 - - -msort/2 - - -msort/3 - - -nextto/3 - - -nth0/3 - - -nth0/4 - - -nth1/3 - - -nth1/4 - - -partition/5 - - -permutation/2 - - -prefix/2 - - -prefix/3 - - -proper_prefix/2 - - -reverse/2 - - -same_length/2 - - -same_length/3 - - -select/3 - - -selectchk/3 - - -select/4 - - -selectchk/4 - - -sort/2 - - -sort/3 - - -split/4 - - -sublist/2 - - -subsequence/3 - - -subsequence/4 - - -substitute/4 - - -subtract/3 - - -suffix/2 - - -suffix/3 - - -proper_suffix/2 - + + + + +listp + + +protocol + + + +append/2 + + +append/3 + + +delete/3 + + +delete_matches/3 + + +empty/1 + + +flatten/2 + + +hamming_distance/3 + + +keysort/2 + + +last/2 + + +length/2 + + +max/2 + + +member/2 + + +memberchk/2 + + +min/2 + + +msort/2 + + +msort/3 + + +nextto/3 + + +nth0/3 + + +nth0/4 + + +nth1/3 + + +nth1/4 + + +partition/5 + + +permutation/2 + + +prefix/2 + + +prefix/3 + + +proper_prefix/2 + + +reverse/2 + + +same_length/2 + + +same_length/3 + + +select/3 + + +selectchk/3 + + +select/4 + + +selectchk/4 + + +sort/2 + + +sort/3 + + +split/4 + + +sublist/2 + + +subsequence/3 + + +subsequence/4 + + +substitute/4 + + +subtract/3 + + +suffix/2 + + +suffix/3 + + +proper_suffix/2 + @@ -1158,17 +1166,17 @@ list - - -list - - -prototype - - - -as_difflist/2 - + + +list + + +prototype + + + +as_difflist/2 + @@ -1176,113 +1184,113 @@ list->compound - - + + -extends +extends list->listp - - + + -implements +implements type - - -type - - -prototype - - - -type/1 - - -valid/2 - - -check/3 - - -check/2 - + + +type + + +prototype + + + +type/1 + + +valid/2 + + +check/3 + + +check/2 + - + arbitrary - - - - - -arbitrary - - -category - - - -arbitrary/1 - - -arbitrary/2 - - -shrink/3 - + + + + + +arbitrary + + +category + + + +arbitrary/1 + + +arbitrary/2 + + +shrink/3 + - + type->arbitrary - - - - + + + + -complements +complements pairs - - -pairs - - -prototype - - - -keys_values/3 - - -keys/2 - - -values/2 - - -transpose/2 - - -map/3 - + + +pairs + + +prototype + + + +keys_values/3 + + +keys/2 + + +values/2 + + +transpose/2 + + +map/3 + @@ -1290,13 +1298,13 @@ callable - - -callable - - -prototype - + + +callable + + +prototype + @@ -1304,89 +1312,89 @@ callable->term - - + + -extends +extends characterp - - - - -characterp - - -protocol - - - -is_ascii/1 - - -is_alphanumeric/1 - - -is_alpha/1 - - -is_letter/1 - - -is_bin_digit/1 - - -is_octal_digit/1 - - -is_dec_digit/1 - - -is_hex_digit/1 - - -is_lower_case/1 - - -is_upper_case/1 - - -is_vowel/1 - - -is_white_space/1 - - -is_layout/1 - - -is_quote/1 - - -is_punctation/1 - - -is_period/1 - - -is_control/1 - - -is_newline/1 - - -is_end_of_line/1 - - -parenthesis/2 - - -lower_upper/2 - + + + + +characterp + + +protocol + + + +is_ascii/1 + + +is_alphanumeric/1 + + +is_alpha/1 + + +is_letter/1 + + +is_bin_digit/1 + + +is_octal_digit/1 + + +is_dec_digit/1 + + +is_hex_digit/1 + + +is_lower_case/1 + + +is_upper_case/1 + + +is_vowel/1 + + +is_white_space/1 + + +is_layout/1 + + +is_quote/1 + + +is_punctation/1 + + +is_period/1 + + +is_control/1 + + +is_newline/1 + + +is_end_of_line/1 + + +parenthesis/2 + + +lower_upper/2 + @@ -1394,13 +1402,13 @@ character - - -character - - -prototype - + + +character + + +prototype + @@ -1408,33 +1416,33 @@ character->atom - - + + -extends +extends character->characterp - - + + -implements +implements natural - - -natural - - -prototype - + + +natural + + +prototype + @@ -1442,23 +1450,23 @@ natural->integer - - + + -extends +extends list(Type) - - -list(Type) - - -prototype - + + +list(Type) + + +prototype + @@ -1466,30 +1474,30 @@ list(Type)->list - - + + -extends +extends difflist - - -difflist - - -prototype - - - -add/3 - - -as_list/2 - + + +difflist + + +prototype + + + +add/3 + + +as_list/2 + @@ -1497,66 +1505,66 @@ difflist->compound - - + + -extends +extends difflist->listp - - + + -implements +implements numberlistp - - - - -numberlistp - - -protocol - - - -product/2 - - -sum/2 - - -average/2 - - -euclidean_norm/2 - - -chebyshev_norm/2 - - -manhattan_norm/2 - - -euclidean_distance/3 - - -chebyshev_distance/3 - - -manhattan_distance/3 - - -scalar_product/3 - + + + + +numberlistp + + +protocol + + + +product/2 + + +sum/2 + + +average/2 + + +euclidean_norm/2 + + +chebyshev_norm/2 + + +manhattan_norm/2 + + +euclidean_distance/3 + + +chebyshev_distance/3 + + +manhattan_distance/3 + + +scalar_product/3 + @@ -1564,13 +1572,13 @@ numberlist - - -numberlist - - -prototype - + + +numberlist + + +prototype + @@ -1578,102 +1586,102 @@ numberlist->list - - + + -extends +extends numberlist->numberlistp - - + + -implements +implements varlistp - - - - -varlistp - - -protocol - - - -append/3 - - -delete/3 - - -empty/1 - - -flatten/2 - - -last/2 - - -length/2 - - -memberchk/2 - - -nextto/3 - - -nth0/3 - - -nth0/4 - - -nth1/3 - - -nth1/4 - - -permutation/2 - - -prefix/2 - - -reverse/2 - - -same_length/2 - - -select/3 - - -sublist/2 - - -subtract/3 - - -suffix/2 - - -valid/1 - - -check/1 - + + + + +varlistp + + +protocol + + + +append/3 + + +delete/3 + + +empty/1 + + +flatten/2 + + +last/2 + + +length/2 + + +memberchk/2 + + +nextto/3 + + +nth0/3 + + +nth0/4 + + +nth1/3 + + +nth1/4 + + +permutation/2 + + +prefix/2 + + +reverse/2 + + +same_length/2 + + +select/3 + + +sublist/2 + + +subtract/3 + + +suffix/2 + + +valid/1 + + +check/1 + @@ -1681,13 +1689,13 @@ varlist - - -varlist - - -prototype - + + +varlist + + +prototype + @@ -1695,53 +1703,53 @@ varlist->varlistp - - + + -implements +implements queuep - - - - -queuep - - -protocol - - - -empty/1 - - -head/2 - - -join/3 - - -join_all/3 - - -jump/3 - - -jump_all/3 - - -length/2 - - -serve/3 - - -as_list/2 - + + + + +queuep + + +protocol + + + +empty/1 + + +head/2 + + +join/3 + + +join_all/3 + + +jump/3 + + +jump_all/3 + + +length/2 + + +serve/3 + + +as_list/2 + @@ -1749,13 +1757,13 @@ queue - - -queue - - -prototype - + + +queue + + +prototype + @@ -1763,99 +1771,99 @@ queue->compound - - + + -extends +extends queue->queuep - - + + -implements +implements dictionaryp - - - - -dictionaryp - - -protocol - - - -as_dictionary/2 - - -as_list/2 - - -clone/3 - - -clone/4 - - -insert/4 - - -delete/4 - - -update/4 - - -update/5 - - -empty/1 - - -lookup/3 - - -previous/4 - - -next/4 - - -min/3 - - -max/3 - - -delete_min/4 - - -delete_max/4 - - -keys/2 - - -map/2 - - -map/3 - - -apply/4 - - -size/2 - + + + + +dictionaryp + + +protocol + + + +as_dictionary/2 + + +as_list/2 + + +clone/3 + + +clone/4 + + +insert/4 + + +delete/4 + + +update/4 + + +update/5 + + +empty/1 + + +lookup/3 + + +previous/4 + + +next/4 + + +min/3 + + +max/3 + + +delete_min/4 + + +delete_max/4 + + +keys/2 + + +map/2 + + +map/3 + + +apply/4 + + +size/2 + @@ -1863,23 +1871,23 @@ bintree - - -bintree - - -prototype - - - -preorder/2 - - -inorder/2 - - -postorder/2 - + + +bintree + + +prototype + + + +preorder/2 + + +inorder/2 + + +postorder/2 + @@ -1887,37 +1895,37 @@ bintree->compound - - + + -extends +extends bintree->dictionaryp - - + + -implements +implements rbtree - - -rbtree - - -prototype - - - -partial_map/4 - + + +rbtree + + +prototype + + + +partial_map/4 + @@ -1925,99 +1933,99 @@ rbtree->compound - - + + -extends +extends rbtree->dictionaryp - - + + -implements +implements setp - - - - -setp - - -protocol - - - -delete/3 - - -disjoint/2 - - -equal/2 - - -empty/1 - - -insert/3 - - -insert_all/3 - - -intersect/2 - - -intersection/3 - - -intersection/4 - - -length/2 - - -member/2 - - -memberchk/2 - - -powerset/2 - - -product/3 - - -select/3 - - -selectchk/3 - - -subset/2 - - -subtract/3 - - -symdiff/3 - - -union/3 - - -union/4 - + + + + +setp + + +protocol + + + +delete/3 + + +disjoint/2 + + +equal/2 + + +empty/1 + + +insert/3 + + +insert_all/3 + + +intersect/2 + + +intersection/3 + + +intersection/4 + + +length/2 + + +member/2 + + +memberchk/2 + + +powerset/2 + + +product/3 + + +select/3 + + +selectchk/3 + + +subset/2 + + +subtract/3 + + +symdiff/3 + + +union/3 + + +union/4 + @@ -2025,13 +2033,13 @@ set - - -set - - -prototype - + + +set + + +prototype + @@ -2039,33 +2047,33 @@ set->compound - - + + -extends +extends set->setp - - + + -implements +implements set(Type) - - -set(Type) - - -prototype - + + +set(Type) + + +prototype + @@ -2073,56 +2081,56 @@ set(Type)->set - - + + -extends +extends heapp - - - - -heapp - - -protocol - - - -insert/4 - - -insert_all/3 - - -delete/4 - - -merge/3 - - -empty/1 - - -size/2 - - -as_list/2 - - -as_heap/2 - - -top/3 - - -top_next/5 - + + + + +heapp + + +protocol + + + +insert/4 + + +insert_all/3 + + +delete/4 + + +merge/3 + + +empty/1 + + +size/2 + + +as_list/2 + + +as_heap/2 + + +top/3 + + +top_next/5 + @@ -2130,13 +2138,13 @@ heap(Order) - - -heap(Order) - - -prototype - + + +heap(Order) + + +prototype + @@ -2144,33 +2152,33 @@ heap(Order)->compound - - + + -extends +extends heap(Order)->heapp - - + + -implements +implements minheap - - -minheap - - -prototype - + + +minheap + + +prototype + @@ -2178,23 +2186,23 @@ minheap->heap(Order) - - + + -extends +extends maxheap - - -maxheap - - -prototype - + + +maxheap + + +prototype + @@ -2202,44 +2210,44 @@ maxheap->heap(Order) - - + + -extends +extends comparingp - - - - -comparingp - - -protocol - - - -(<)/2 - - -(=<)/2 - - -(>)/2 - - -(>=)/2 - - -(=:=)/2 - - -(=\=)/2 - + + + + +comparingp + + +protocol + + + +(<)/2 + + +(=<)/2 + + +(>)/2 + + +(>=)/2 + + +(=:=)/2 + + +(=\=)/2 + @@ -2247,55 +2255,58 @@ randomp - - - - -randomp - - -protocol - - - -random/1 - - -between/3 - - -member/2 - - -select/3 - - -permutation/2 - - -sequence/4 - - -set/4 - - -random/3 - - -randseq/4 - - -randset/4 - - -reset_seed/0 - - -get_seed/1 - - -set_seed/1 - + + + + +randomp + + +protocol + + + +random/1 + + +between/3 + + +member/2 + + +select/3 + + +permutation/2 + + +sequence/4 + + +set/4 + + +random/3 + + +randseq/4 + + +randset/4 + + +reset_seed/0 + + +get_seed/1 + + +set_seed/1 + + +randomize/1 + @@ -2303,13 +2314,13 @@ random - - -random - - -prototype - + + +random + + +prototype + @@ -2317,51 +2328,75 @@ random->randomp - - + + -implements +implements + + + +frandom + + + +frandom + + +prototype + + + + + + +frandom->randomp + + + + + +implements - + datep - - - - - -datep - - -protocol - - - -today/3 - - -leap_year/1 - - -name_of_day/3 - - -name_of_month/3 - - -days_in_month/3 - - -valid/3 - + + + + + +datep + + +protocol + + + +today/3 + + +leap_year/1 + + +name_of_day/3 + + +name_of_month/3 + + +days_in_month/3 + + +valid/3 + - + date - + date @@ -2373,45 +2408,45 @@ - + date->datep - - - + + + -implements +implements - + timep - - - - - -timep - - -protocol - - - -now/3 - - -cpu_time/1 - - -valid/3 - + + + + + +timep + + +protocol + + + +now/3 + + +cpu_time/1 + + +valid/3 + - + time - + time @@ -2423,129 +2458,129 @@ - + time->timep - - - + + + -implements +implements - + event_registryp - - - - - -event_registryp - - -protocol - - - -monitors/1 - - -monitor/1 - - -monitored/1 - - -monitor/4 - - -set_monitor/4 - - -del_monitors/4 - - -del_monitors/0 - + + + + + +event_registryp + + +protocol + + + +monitors/1 + + +monitor/1 + + +monitored/1 + + +monitor/4 + + +set_monitor/4 + + +del_monitors/4 + + +del_monitors/0 + - + event_registry - - - -event_registry - - -prototype - + + + +event_registry + + +prototype + - + event_registry->event_registryp - - - + + + -implements +implements - + before_event_registry - - - -before_event_registry - - -prototype - + + + +before_event_registry + + +prototype + - + before_event_registry->event_registryp - - - + + + -implements +implements - + after_event_registry - - - -after_event_registry - - -prototype - + + + +after_event_registry + + +prototype + - + after_event_registry->event_registryp - - - + + + -implements +implements - + monitorp - + @@ -2581,9 +2616,9 @@ - + monitor - + @@ -2597,9 +2632,9 @@ - + monitor->monitorp - + @@ -2607,9 +2642,9 @@ implements - + observer - + @@ -2627,9 +2662,9 @@ - + subject - + @@ -2659,83 +2694,83 @@ - + hierarchyp - - - - - -hierarchyp - - -protocol - - - -ancestor/1 - - -ancestors/1 - - -leaf/1 - - -leaves/1 - - -descendant/1 - - -descendants/1 - + + + + + +hierarchyp + + +protocol + + + +ancestor/1 + + +ancestors/1 + + +leaf/1 + + +leaves/1 + + +descendant/1 + + +descendants/1 + - + proto_hierarchyp - - - - - -proto_hierarchyp - - -protocol - - - -parent/1 - - -parents/1 - - -extension/1 - - -extensions/1 - + + + + + +proto_hierarchyp + + +protocol + + + +parent/1 + + +parents/1 + + +extension/1 + + +extensions/1 + - + proto_hierarchyp->hierarchyp - - - + + + -extends +extends - + proto_hierarchy - + @@ -2749,94 +2784,94 @@ - + proto_hierarchy->proto_hierarchyp - - - + + + -implements +implements - + class_hierarchyp - - - - - -class_hierarchyp - - -protocol - - - -class/1 - - -classes/1 - - -instance/1 - - -instances/1 - - -subclass/1 - - -subclasses/1 - - -superclass/1 - - -superclasses/1 - - -leaf_instance/1 - - -leaf_instances/1 - - -leaf_class/1 - - -leaf_classes/1 - - -descendant_instance/1 - - -descendant_instances/1 - - -descendant_class/1 - - -descendant_classes/1 - + + + + + +class_hierarchyp + + +protocol + + + +class/1 + + +classes/1 + + +instance/1 + + +instances/1 + + +subclass/1 + + +subclasses/1 + + +superclass/1 + + +superclasses/1 + + +leaf_instance/1 + + +leaf_instances/1 + + +leaf_class/1 + + +leaf_classes/1 + + +descendant_instance/1 + + +descendant_instances/1 + + +descendant_class/1 + + +descendant_classes/1 + - + class_hierarchyp->hierarchyp - - - + + + -extends +extends - + class_hierarchy - + @@ -2850,102 +2885,102 @@ - + class_hierarchy->class_hierarchyp - - - + + + -implements +implements - + metap - - - - - -metap - - -protocol - - - -include/3 - - -exclude/3 - - -findall_member/4 - - -findall_member/5 - - -partition/4 - - -partition/6 - - -fold_left/4 - - -fold_left_1/3 - - -scan_left/4 - - -scan_left_1/3 - - -fold_right/4 - - -fold_right_1/3 - - -scan_right/4 - - -scan_right_1/3 - - -map/2 - - -map/3 - - -map/4 - - -map/5 - - -map/6 - - -map/7 - - -map/8 - - -map_reduce/5 - + + + + + +metap + + +protocol + + + +include/3 + + +exclude/3 + + +findall_member/4 + + +findall_member/5 + + +partition/4 + + +partition/6 + + +fold_left/4 + + +fold_left_1/3 + + +scan_left/4 + + +scan_left_1/3 + + +fold_right/4 + + +fold_right_1/3 + + +scan_right/4 + + +scan_right_1/3 + + +map/2 + + +map/3 + + +map/4 + + +map/5 + + +map/6 + + +map/7 + + +map/8 + + +map_reduce/5 + - + meta - + meta @@ -2957,63 +2992,63 @@ - + meta->metap - - - + + + -implements +implements - + loopp - - - - - -loopp - - -protocol - - - -whiledo/2 - - -dowhile/2 - - -foreach/3 - - -forto/3 - - -forto/4 - - -forto/5 - - -fordownto/3 - - -fordownto/4 - - -fordownto/5 - + + + + + +loopp + + +protocol + + + +whiledo/2 + + +dowhile/2 + + +foreach/3 + + +forto/3 + + +forto/4 + + +forto/5 + + +fordownto/3 + + +fordownto/4 + + +fordownto/5 + - + loop - + loop @@ -3025,119 +3060,119 @@ - + loop->loopp - - - + + + -implements +implements - + statisticsp - - - - - -statisticsp - - -protocol - - - -product/2 - - -sum/2 - - -max/2 - - -min/2 - - -range/2 - - -arithmetic_mean/2 - - -geometric_mean/2 - - -harmonic_mean/2 - - -median/2 - - -average_deviation/3 - - -mean_deviation/2 - - -median_deviation/2 - - -standard_deviation/2 - - -coefficient_of_variation/2 - - -relative_standard_deviation/2 - - -skewness/2 - - -kurtosis/2 - - -variance/2 - - -valid/1 - + + + + + +statisticsp + + +protocol + + + +product/2 + + +sum/2 + + +max/2 + + +min/2 + + +range/2 + + +arithmetic_mean/2 + + +geometric_mean/2 + + +harmonic_mean/2 + + +median/2 + + +average_deviation/3 + + +mean_deviation/2 + + +median_deviation/2 + + +standard_deviation/2 + + +coefficient_of_variation/2 + + +relative_standard_deviation/2 + + +skewness/2 + + +kurtosis/2 + + +variance/2 + + +valid/1 + - + statistics - - - - - -statistics - - -category - + + + + + +statistics + + +category + - + statistics->statisticsp - - - + + + -implements +implements - + population - + population @@ -3149,20 +3184,20 @@ - + population->statistics - - - - + + + + -imports +imports - + sample - + sample @@ -3174,20 +3209,20 @@ - + sample->statistics - - - - + + + + -imports +imports - + intervalp - + @@ -3247,9 +3282,9 @@ - + interval - + interval @@ -3261,9 +3296,9 @@ - + interval->intervalp - + @@ -3271,9 +3306,9 @@ implements - + loggingp - + @@ -3309,9 +3344,9 @@ - + logging - + @@ -3325,9 +3360,9 @@ - + logging->loggingp - + @@ -3335,9 +3370,9 @@ implements - + logger - + logger @@ -3349,9 +3384,9 @@ - + logger->loggingp - + @@ -3359,9 +3394,9 @@ implements - + gensym - + gensym @@ -3383,9 +3418,9 @@ - + meta_compiler - + meta_compiler @@ -3397,35 +3432,35 @@ - + expanding - - - - - -expanding - - -built-in protocol - + + + + + +expanding + + +built-in protocol + - + meta_compiler->expanding - - - + + + -implements +implements - + assignvarsp - + @@ -3458,9 +3493,9 @@ - + assignvars - + assignvars @@ -3472,9 +3507,9 @@ - + assignvars->assignvarsp - + @@ -3482,9 +3517,9 @@ implements - + hook_pipeline(Pipeline) - + hook_pipeline(Pipeline) @@ -3496,19 +3531,19 @@ - + hook_pipeline(Pipeline)->expanding - - - + + + -implements +implements - + hook_set(Set) - + hook_set(Set) @@ -3520,19 +3555,19 @@ - + hook_set(Set)->expanding - - - + + + -implements +implements - + java_access_protocol - + @@ -3562,9 +3597,9 @@ - + java_utils_protocol - + @@ -3621,9 +3656,9 @@ - + java(Reference,ReturnValue) - + java(Reference,ReturnValue) @@ -3635,9 +3670,9 @@ - + java(Reference,ReturnValue)->java_access_protocol - + @@ -3645,35 +3680,35 @@ implements - + forwarding - - - - - -forwarding - - -built-in protocol - + + + + + +forwarding + + +built-in protocol + - + java(Reference,ReturnValue)->forwarding - - - + + + -implements +implements - + java(Reference) - + java(Reference) @@ -3685,9 +3720,9 @@ - + java(Reference)->java(Reference,ReturnValue) - + @@ -3695,9 +3730,9 @@ extends - + java - + java @@ -3709,9 +3744,9 @@ - + java->java_utils_protocol - + @@ -3719,9 +3754,9 @@ implements - + counters - + @@ -3751,9 +3786,9 @@ - + streamvars - + streamvars diff --git a/docs/predicate_index.html b/docs/predicate_index.html index 36f282d5d6..eb0c343ea9 100644 --- a/docs/predicate_index.html +++ b/docs/predicate_index.html @@ -3975,6 +3975,16 @@

    +
    +
    + randomize/1 +
    +
    + + randomp + +
    +
    randseq/4 diff --git a/docs/random_0.html b/docs/random_0.html index 9421541c40..8cf2f83e37 100644 --- a/docs/random_0.html +++ b/docs/random_0.html @@ -11,7 +11,7 @@

    object

    random

    -

    Portable random number generator predicates.

    +

    Portable random number generator predicates. Core predicates originally written by Richard O'Keefe.

    @@ -23,11 +23,11 @@

    random

    version:
    - 2.0 + 2.1
    date:
    - 2016/8/23 + 2017/2/25
    @@ -90,7 +90,10 @@

    (none)

    Remarks

    -

    (none)

    +
    +
    Multiple random number generators
    +
    To define multiple random number generators, simply extend this object. The derived objects must send to self the reset_seed/0 message.
    +
    diff --git a/docs/randomp_0.html b/docs/randomp_0.html index d3e3e1a386..a977e98eb6 100644 --- a/docs/randomp_0.html +++ b/docs/randomp_0.html @@ -23,11 +23,11 @@

    randomp

    version:
    - 2.0 + 2.1
    date:
    - 2016/8/19 + 2017/2/25
    @@ -254,7 +254,7 @@

    randset/4

    reset_seed/0

    -

    Resets the random generator seed to its default value. Deprecated. Use get_seed/1 and set_seed/1 instead if you need reproducibility.

    +

    Resets the random generator seed to its default value. Use get_seed/1 and set_seed/1 instead if you need reproducibility.

    compilation flags:
    @@ -270,7 +270,7 @@

    reset_seed/0

    get_seed/1

    -

    Gets the current random generator seed. Seed should be regarded as an opaque ground term

    +

    Gets the current random generator seed. Seed should be regarded as an opaque ground term.

    compilation flags:
    @@ -307,6 +307,26 @@

    set_seed/1

    +
    +

    randomize/1

    +
    +

    Randomizes the random generator using a positive integer to compute a new seed.

    +
    +
    +
    compilation flags:
    +
    + static +
    +
    template:
    +
    + randomize(Seed) +
    +
    mode – number of proofs:
    +
    + randomize(+positive_integer) – one +
    +
    +

    Protected interface

    diff --git a/docs/tools_inheritance_diagram.svg b/docs/tools_inheritance_diagram.svg index 341e42be56..1709cff543 100644 --- a/docs/tools_inheritance_diagram.svg +++ b/docs/tools_inheritance_diagram.svg @@ -1,7 +1,7 @@ - tools Logtalk development tools -Generated on 2017/01/29, 18:02 +Generated on 2017/02/25, 11:46 cluster_rlibrary_tools @@ -403,6 +403,22 @@ + +cluster_library_wrapper + + +wrapper + + + + +cluster_file_/Users/pmoura/logtalk/tools/wrapper/wrapper.lgt + + +wrapper.lgt + + + cluster_library_metrics @@ -443,22 +459,6 @@ - -cluster_library_wrapper - - -wrapper - - - - -cluster_file_/Users/pmoura/logtalk/tools/wrapper/wrapper.lgt - - -wrapper.lgt - - - assertions(Mode) diff --git a/library/frandom.lgt b/library/frandom.lgt new file mode 100644 index 0000000000..f61ab75d82 --- /dev/null +++ b/library/frandom.lgt @@ -0,0 +1,259 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% This file is part of Logtalk +% Copyright 1998-2017 Paulo Moura +% +% Licensed under the Apache License, Version 2.0 (the "License"); +% you may not use this file except in compliance with the License. +% You may obtain a copy of the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, +% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +% See the License for the specific language governing permissions and +% limitations under the License. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +:- object(frandom, + implements(randomp)). + + :- info([ + version is 2.1, + author is 'Paulo Moura', + date is 2017/02/25, + comment is 'Fast portable random number generator predicates. Core predicates originally written by Richard O''Keefe.', + remarks is [ + 'Single random number generator' - 'This object provides a faster version of the "random" library object but does not support being extended to define multiple random number generators.' + ] + ]). + + :- uses(list, [ + length/2, nth1/3 + ]). + + :- synchronized([ + random/1, random/3, + sequence/4, set/4, permutation/2, + randseq/4, randset/4, + reset_seed/0, get_seed/1, set_seed/1 + ]). + + :- initialization(reset_seed). + + :- private(seed_/3). + :- dynamic(seed_/3). + :- mode(seed_(-integer, -integer, -integer), one). + :- info(seed_/3, [ + comment is 'Stores the current random generator seed values.', + argnames is ['S0', 'S1', 'S2'] + ]). + + random(Random) :- + retract(seed_(A0, A1, A2)), + random(A0, A1, A2, B0, B1, B2, Random), + asserta(seed_(B0, B1, B2)). + + random(A0, A1, A2, B0, B1, B2, Random) :- + B0 is (A0*171) mod 30269, + B1 is (A1*172) mod 30307, + B2 is (A2*170) mod 30323, + Float is A0/30269 + A1/30307 + A2/30323, + Random is Float - truncate(Float). + + between(Lower, Upper, Random) :- + integer(Lower), + integer(Upper), + Upper >= Lower, + random(Float), + Random is truncate((Float * (Upper - Lower + 1) + Lower)). + + member(Random, List) :- + length(List, Length), + random(Float), + Index is truncate(Float*Length+1), + nth1(Index, List, Random). + + select(Random, List, Rest) :- + length(List, Length), + random(Float), + Index is truncate(Float*Length+1), + select(1, Index, Random, List, Rest). + + select(Index, Index, Random, [Random| Rest], Rest) :- + !. + select(Current, Index, Random, [Head| Tail], [Head| Rest]) :- + Next is Current + 1, + select(Next, Index, Random, Tail, Rest). + + sequence(Length, Lower, Upper, Sequence) :- + integer(Length), + Length >= 0, + integer(Lower), + integer(Upper), + Upper >= Lower, + retract(seed_(A0, A1, A2)), + sequence(Length, Lower, Upper, A0, A1, A2, B0, B1, B2, Sequence), + asserta(seed_(B0, B1, B2)). + + sequence(0, _, _, S0, S1, S2, S0, S1, S2, []) :- + !. + sequence(N, Lower, Upper, A0, A1, A2, S0, S1, S2, [Random| Sequence]) :- + N2 is N - 1, + random(A0, A1, A2, B0, B1, B2, Float), + Random is truncate(Float * (Upper - Lower + 1) + Lower), + sequence(N2, Lower, Upper, B0, B1, B2, S0, S1, S2, Sequence). + + set(Length, Lower, Upper, Set) :- + integer(Length), + Length >= 0, + integer(Lower), + integer(Upper), + Upper >= Lower, + Length =< Upper - Lower + 1, + retract(seed_(A0, A1, A2)), + set(Length, Lower, Upper, A0, A1, A2, B0, B1, B2, [], Set), + asserta(seed_(B0, B1, B2)). + + set(0, _, _, S0, S1, S2, S0, S1, S2, List, Set) :- + !, + sort(List, Set). + set(N, Lower, Upper, A0, A1, A2, S0, S1, S2, Acc, Set) :- + random(A0, A1, A2, B0, B1, B2, Float), + Random is truncate(Float * (Upper - Lower + 1) + Lower), + ( not_member(Acc, Random) -> + N2 is N - 1, + set(N2, Lower, Upper, B0, B1, B2, S0, S1, S2, [Random| Acc], Set) + ; set(N, Lower, Upper, B0, B1, B2, S0, S1, S2, Acc, Set) + ). + + permutation(List, Permutation) :- + retract(seed_(A0, A1, A2)), + add_random_key(List, A0, A1, A2, B0, B1, B2, KeyList), + asserta(seed_(B0, B1, B2)), + keysort(KeyList, SortedKeyList), + remove_random_key(SortedKeyList, Permutation). + + add_random_key([], S0, S1, S2, S0, S1, S2, []). + add_random_key([Head| Tail], A0, A1, A2, S0, S1, S2, [Random-Head| KeyTail]) :- + random(A0, A1, A2, B0, B1, B2, Random), + add_random_key(Tail, B0, B1, B2, S0, S1, S2, KeyTail). + + remove_random_key([], []). + remove_random_key([_-Head| KeyTail], [Head| Tail]) :- + remove_random_key(KeyTail, Tail). + + random(Lower, Upper, Random) :- + integer(Lower), + integer(Upper), + Upper >= Lower, + !, + random(Float), + Random is truncate((Float * (Upper - Lower) + Lower)). + random(Lower, Upper, Random) :- + float(Lower), + float(Upper), + Upper >= Lower, + random(Float), + Random is Float * (Upper-Lower) + Lower. + + randseq(Length, Lower, Upper, Sequence) :- + integer(Length), + Length >= 0, + integer(Lower), + integer(Upper), + Upper >= Lower, + !, + retract(seed_(A0, A1, A2)), + randseq(Length, Lower, Upper, (A0, A1, A2), (B0, B1, B2), List), + asserta(seed_(B0, B1, B2)), + map_truncate(List, Sequence). + randseq(Length, Lower, Upper, Sequence) :- + integer(Length), + Length >= 0, + float(Lower), + float(Upper), + Upper >= Lower, + retract(seed_(A0, A1, A2)), + randseq(Length, Lower, Upper, (A0, A1, A2), (B0, B1, B2), Sequence), + asserta(seed_(B0, B1, B2)). + + randseq(0, _, _, Seed, Seed, []) :- + !. + randseq(N, Lower, Upper, (A0, A1, A2), (C0, C1, C2), [Random| List]) :- + N2 is N - 1, + random(A0, A1, A2, B0, B1, B2, R), + Random is R * (Upper-Lower)+Lower, + randseq(N2, Lower, Upper, (B0, B1, B2), (C0, C1, C2), List). + + map_truncate([], []). + map_truncate([Float| Floats], [Integer| Integers]) :- + Integer is truncate(Float), + map_truncate(Floats, Integers). + + randset(Length, Lower, Upper, Set) :- + integer(Length), + Length >= 0, + integer(Lower), + integer(Upper), + Upper >= Lower, + Length =< Upper - Lower, + !, + retract(seed_(A0, A1, A2)), + randset(Length, Lower, Upper, (A0, A1, A2), (B0, B1, B2), [], Set), + asserta(seed_(B0, B1, B2)). + randset(Length, Lower, Upper, Set) :- + integer(Length), + Length >= 0, + float(Lower), + float(Upper), + Upper >= Lower, + retract(seed_(A0, A1, A2)), + randset(Length, Lower, Upper, (A0, A1, A2), (B0, B1, B2), [], Set), + asserta(seed_(B0, B1, B2)). + + randset(0, _, _, Seed, Seed, List, Set) :- + !, + sort(List, Set). + randset(N, Lower, Upper, (A0, A1, A2), (C0, C1, C2), Acc, Set) :- + random(A0, A1, A2, B0, B1, B2, Float), + Float2 is Float * (Upper-Lower) + Lower, + ( integer(Lower) -> + Random is truncate(Float2) + ; Random is Float2 + ), + ( not_member(Acc, Random) -> + N2 is N - 1, + randset(N2, Lower, Upper, (B0, B1, B2), (C0, C1, C2), [Random| Acc], Set) + ; randset(N, Lower, Upper, (B0, B1, B2), (C0, C1, C2), Acc, Set) + ). + + not_member([], _). + not_member([H| T], R) :- + H =\= R, + not_member(T, R). + + reset_seed :- + retractall(seed_(_, _, _)), + asserta(seed_(3172, 9814, 20125)). + + get_seed(seed(S0, S1, S2)) :- + seed_(S0, S1, S2). + + set_seed(seed(S0, S1, S2)) :- + retractall(seed_(_, _, _)), + asserta(seed_(S0, S1, S2)). + + randomize(Seed) :- + integer(Seed), + Seed > 0, + retractall(seed_(_, _, _)), + S0 is Seed mod 30269, + S1 is Seed mod 30307, + S2 is Seed mod 30323, + asserta(seed_(S0, S1, S2)). + +:- end_object. diff --git a/library/random.lgt b/library/random.lgt index 690c0b59af..1faea6b54d 100644 --- a/library/random.lgt +++ b/library/random.lgt @@ -22,10 +22,13 @@ implements(randomp)). :- info([ - version is 2.0, + version is 2.1, author is 'Paulo Moura', - date is 2016/08/23, - comment is 'Portable random number generator predicates.' + date is 2017/02/25, + comment is 'Portable random number generator predicates. Core predicates originally written by Richard O''Keefe.', + remarks is [ + 'Multiple random number generators' - 'To define multiple random number generators, simply extend this object. The derived objects must send to self the reset_seed/0 message.' + ] ]). :- uses(list, [ @@ -240,9 +243,12 @@ get_seed(seed(S0, S1, S2)) :- ::seed_(S0, S1, S2). - set_seed(Seed) :- + set_seed(seed(S0, S1, S2)) :- + ::retractall(seed_(_, _, _)), + ::asserta(seed_(S0, S1, S2)). + + randomize(Seed) :- integer(Seed), - !, Seed > 0, ::retractall(seed_(_, _, _)), S0 is Seed mod 30269, @@ -250,8 +256,4 @@ S2 is Seed mod 30323, ::asserta(seed_(S0, S1, S2)). - set_seed(seed(S0, S1, S2)) :- - ::retractall(seed_(_, _, _)), - ::asserta(seed_(S0, S1, S2)). - :- end_object. diff --git a/library/random.txt b/library/random.txt index 7331242e53..977cc00e77 100644 --- a/library/random.txt +++ b/library/random.txt @@ -17,14 +17,22 @@ limitations under the License. ________________________________________________________________________ -To load all entities in this library load the `random_loader.lgt` -utility file: +To load all entities in this library load the `random_loader.lgt` utility +file: | ?- logtalk_load(library(random_loader)). -The `random` object implements portable random number generators. +The `random` object implements portable random number generators and +supports multiple random number generators, using different seeds, by +defining derived objects. For example: -If you need more than one random number generator, using different -seeds, define new objects as extensions of the `random` object. Be -sure to initialize the seeds of the new random generator objects -by using the `reset_seed/0` message. + :- object(my_random_generator_1, + extends(ramdom)). + + :- intialization(::reset_seed). + + :- end_object. + +The `frandom` object is a faster version of the `random` object but +cannot be extended. Useful when a single random number generator is +required. diff --git a/library/random_loader.lgt b/library/random_loader.lgt index 5704e40470..a7142ea887 100644 --- a/library/random_loader.lgt +++ b/library/random_loader.lgt @@ -20,5 +20,5 @@ :- initialization(( logtalk_load(basic_types_loader), - logtalk_load([randomp, random], [optimize(on)]) + logtalk_load([randomp, random, frandom], [optimize(on)]) )). diff --git a/library/randomp.lgt b/library/randomp.lgt index 3974b4b07b..48827c1b54 100644 --- a/library/randomp.lgt +++ b/library/randomp.lgt @@ -21,9 +21,9 @@ :- protocol(randomp). :- info([ - version is 2.0, + version is 2.1, author is 'Paulo Moura', - date is 2016/08/19, + date is 2017/02/25, comment is 'Random number generator protocol.' ]). @@ -103,13 +103,13 @@ :- public(reset_seed/0). :- mode(reset_seed, one). :- info(reset_seed/0, [ - comment is 'Resets the random generator seed to its default value. Deprecated. Use get_seed/1 and set_seed/1 instead if you need reproducibility.' + comment is 'Resets the random generator seed to its default value. Use get_seed/1 and set_seed/1 instead if you need reproducibility.' ]). :- public(get_seed/1). :- mode(get_seed(-ground), one). :- info(get_seed/1, [ - comment is 'Gets the current random generator seed. Seed should be regarded as an opaque ground term', + comment is 'Gets the current random generator seed. Seed should be regarded as an opaque ground term.', argnames is ['Seed'] ]). @@ -120,4 +120,11 @@ argnames is ['Seed'] ]). + :- public(randomize/1). + :- mode(randomize(+positive_integer), one). + :- info(randomize/1, [ + comment is 'Randomizes the random generator using a positive integer to compute a new seed.', + argnames is ['Seed'] + ]). + :- end_protocol.